.net - c# time-slot calculation (today-givenDate) -
i preparing class calculates penalty library. example: have book. return book 12.11.2009. delay return date. returned book on 30.11.2009. pay penalty money. how can count (november 31 - november 12) on c#?
penalty should calculated business days only. means calculation should take account of weekends , national holidays.
<holiday date="25.11.2009"/> <holiday date="26.11.2009"/> <holiday date="27.11.2009"/>
public int countbusinessdaysbetween(datetime start, datetime end) { int days = end.subtract(start).days; return enumerable.range(0, days) .select(day => start.adddays(day)) .where(date => date.isbusinessday()) .count(); } of course, you have code isbusinessday yourself. don't know definition of business day is. it's highly localized.
also, don't know if want count inclusively or not, might need + 1 on definition of days if so.
Comments
Post a Comment