public static DateTime AddWorkingDays(this DateTime @this, int days) { // start from a weekday while (@this.IsWeekendDay()) { @this = @this.AddDays(1.0); } for (int i = 0; i < days; ++i) { @this = @this.AddDays(1.0); while (@this.IsWeekendDay()) { @this = @this.AddDays(1.0); } } return(@this); }
public void IsWeekendDayTestCase() { var dateTime = new DateTime( 2014, 3, 27 ); var actual = dateTime.IsWeekendDay(); Assert.IsFalse( actual ); dateTime = new DateTime( 2014, 3, 29 ); actual = dateTime.IsWeekendDay(); Assert.IsTrue( actual ); }
public void IsWeekendDay() { // Type var @thisFriday = new DateTime(2013, 11, 22); // Friday var @thisSaturday = new DateTime(2013, 11, 23); // Saturday // Examples bool value1 = @thisFriday.IsWeekendDay(); // return false; bool value2 = @thisSaturday.IsWeekendDay(); // return true; // Unit Test Assert.IsFalse(value1); Assert.IsTrue(value2); }
public static bool IsWeekDay(this DateTime @this) { return([email protected]()); }
public static bool IsNotWorkingDay(this DateTime @this) { return(@this.IsWeekendDay()); }