Skip to content

Instantly share code, notes, and snippets.

@mariochavez
Created September 22, 2010 22:51
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}
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