public Difference ( System.DateTime date ) : System.TimeSpan | ||
date | System.DateTime | |
return | System.TimeSpan |
public void NoFilterTest() { DateTime date1 = new DateTime( 2011, 4, 12 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); Assert.AreEqual( calendarDateDiff.Difference( date1, date1.AddHours( 1 ) ), new TimeSpan( 1, 0, 0 ) ); Assert.AreEqual( calendarDateDiff.Difference( date1, date1.AddHours( -1 ) ), new TimeSpan( -1, 0, 0 ) ); }
public void HourFilterTest() { DateTime date1 = new DateTime( 2011, 9, 11, 18, 0, 0 ); DateTime date2 = new DateTime( 2011, 9, 15, 9, 0, 0 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); calendarDateDiff.WorkingHours.Add( new HourRange( 8, 12 ) ); Assert.AreEqual( calendarDateDiff.Difference( date1, date2 ), new TimeSpan( 74, 0, 0 ) ); Assert.AreEqual( calendarDateDiff.Difference( date2, date1 ), new TimeSpan( -74, 0, 0 ) ); }
public void DayHourFilterTest() { DateTime date1 = new DateTime( 2011, 9, 11, 18, 0, 0 ); DateTime date2 = new DateTime( 2011, 9, 15, 9, 0, 0 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); calendarDateDiff.WorkingDayHours.Add( new DayHourRange( DayOfWeek.Monday, 8, 12 ) ); calendarDateDiff.WorkingDayHours.Add( new DayHourRange( DayOfWeek.Tuesday, 8, 16 ) ); Assert.AreEqual( calendarDateDiff.Difference( date1, date2 ), new TimeSpan( 75, 0, 0 ) ); Assert.AreEqual( calendarDateDiff.Difference( date2, date1 ), new TimeSpan( -75, 0, 0 ) ); }
public void EmptyDiffTest() { DateTime date = new DateTime( 2011, 4, 12 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); Assert.AreEqual( calendarDateDiff.Difference( date, date ), TimeSpan.Zero ); }
public void CalendarDateDiffHourSample() { DateTime date1 = new DateTime( 2011, 9, 11, 18, 0, 0 ); DateTime date2 = new DateTime( 2011, 9, 15, 9, 0, 0 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); calendarDateDiff.WorkingHours.Add( new HourRange( 8, 12 ) ); Console.WriteLine( "CalendarDateDiffHourSample : {0} hours", calendarDateDiff.Difference( date1, date2 ).TotalHours ); // > CalendarDateDiffHourSample : 74 hours Console.WriteLine( "CalendarDateDiffHourSample : {0} hours", calendarDateDiff.Difference( date2, date1 ).TotalHours ); // > CalendarDateDiffHourSample : -74 hours }
public void CalendarDateDiffDayHourSample() { DateTime date1 = new DateTime( 2011, 9, 11, 18, 0, 0 ); DateTime date2 = new DateTime( 2011, 9, 15, 9, 0, 0 ); CalendarDateDiff calendarDateDiff = new CalendarDateDiff(); calendarDateDiff.WorkingDayHours.Add( new DayHourRange( DayOfWeek.Monday, 8, 16 ) ); calendarDateDiff.WorkingDayHours.Add( new DayHourRange( DayOfWeek.Tuesday, 8, 20 ) ); Console.WriteLine( "CalendarDateDiffDayHourSample : {0} hours", calendarDateDiff.Difference( date1, date2 ).TotalHours ); // > CalendarDateDiffHourSample : 67 hours Console.WriteLine( "CalendarDateDiffDayHourSample : {0} hours", calendarDateDiff.Difference( date2, date1 ).TotalHours ); // > CalendarDateDiffHourSample : -67 hours }
public void BusinessHoursSample1() { TimeRange timeRange = new TimeRange( new DateTime( 2012, 4, 05, 10, 30, 00 ), // start calc at 10:30 AM new DateTime( 2012, 4, 10, 23, 59, 59 ) ); CalendarDateDiff dateDiff = new CalendarDateDiff(); dateDiff.WorkingHours.Add( new HourRange( 8, 18 ) ); dateDiff.AddWorkingWeekDays(); TimeSpan nonBusinessHours = dateDiff.Difference( timeRange.Start, timeRange.End ); double businessHours = timeRange.Duration.TotalHours - nonBusinessHours.TotalHours; Console.WriteLine( "business hours: " + businessHours ); // > business hours: 37.5 }