Created
September 22, 2010 22:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def working_days(start_date, end_date) | |
days = [] | |
(start_date..end_date).each { |d| days << d if d.cwday < 6 } | |
days | |
end | |
working_days(Date.today, Date.today + 7).each{|x| puts x.to_s} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BusinessDays | |
{ | |
public static bool WorkingDay(this DateTime date) | |
{ | |
return date.DayOfWeek != DayOfWeek.Saturday && date.DayOfWeek != DayOfWeek.Sunday; | |
} | |
/* this function is used only to collect the dates | |
we are not paying much attention of the implementation */ | |
public static List<DateTime> GetAlldates(DateTime start, DateTime end) | |
{ | |
List<DateTime> dates = new List<DateTime>(); | |
DateTime currLoopDate = start; | |
while (currLoopDate < end) | |
{ | |
dates.Add(currLoopDate); | |
currLoopDate = currLoopDate.AddDays(1); | |
} | |
return dates; | |
} | |
} | |
var dates = BusinessDays.GetAlldates(DateTime.Now, DateTime.Now.AddDays(7)); | |
int getBizDays = dates.Where(day => day.WorkingDay()).Count(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment