// ---------------------------------------------------------------------- protected override bool OnVisitDay( Day day, CalendarPeriodCollectorContext context ) { // allow only the last day of the month if ( day.Month == day.AddDays( TimeSpec.DaysPerWeek ).Month ) { return false; } return base.OnVisitDay( day, context ); }
public void AddDaysTest() { DateTime now = ClockProxy.Clock.Now; DateTime nowDay = new DateTime( now.Year, now.Month, now.Day ); Day day = new Day( now, TimeCalendar.NewEmptyOffset() ); Assert.AreEqual( day.AddDays( 0 ), day ); DateTime previousDay = nowDay.AddDays( -1 ); Assert.AreEqual( day.AddDays( -1 ).Year, previousDay.Year ); Assert.AreEqual( day.AddDays( -1 ).Month, previousDay.Month ); Assert.AreEqual( day.AddDays( -1 ).DayValue, previousDay.Day ); DateTime nextDay = nowDay.AddDays( 1 ); Assert.AreEqual( day.AddDays( 1 ).Year, nextDay.Year ); Assert.AreEqual( day.AddDays( 1 ).Month, nextDay.Month ); Assert.AreEqual( day.AddDays( 1 ).DayValue, nextDay.Day ); }
public void GetPreviousDayTest() { Day day = new Day(); Assert.AreEqual( day.GetPreviousDay(), day.AddDays( -1 ) ); }
public void GetNextDayTest() { Day day = new Day(); Assert.AreEqual( day.GetNextDay(), day.AddDays( 1 ) ); }
public void SimpleBackwardTest() { Day start = new Day( new DateTime( 2011, 2, 15 ) ); DaySeeker daySeeker = new DaySeeker( SeekDirection.Backward ); Day day1 = daySeeker.FindDay( start, 0 ); Assert.IsTrue( day1.IsSamePeriod( start ) ); Day day2 = daySeeker.FindDay( start, 1 ); Assert.IsTrue( day2.IsSamePeriod( start.GetPreviousDay() ) ); Day day3 = daySeeker.FindDay( start, 100 ); Assert.IsTrue( day3.IsSamePeriod( start.AddDays( -100 ) ) ); }
public void SimpleForwardTest() { Day start = new Day( new DateTime( 2011, 2, 15 ) ); DaySeeker daySeeker = new DaySeeker(); Day day1 = daySeeker.FindDay( start, 0 ); Assert.IsTrue( day1.IsSamePeriod( start ) ); Day day2 = daySeeker.FindDay( start, 1 ); Assert.IsTrue( day2.IsSamePeriod( start.GetNextDay() ) ); Day day3 = daySeeker.FindDay( start, 100 ); Assert.IsTrue( day3.IsSamePeriod( start.AddDays( 100 ) ) ); }
// ---------------------------------------------------------------------- private void SelectPeriod( PeriodSelectType periodSelectType ) { int offset = 0; switch ( periodSelectType ) { case PeriodSelectType.Previous: offset = -1; break; case PeriodSelectType.Current: ResetWorkingPeriod(); return; case PeriodSelectType.Next: offset = 1; break; } switch ( WorkingTimePeriod ) { case TimePeriodMode.Year: Year year = new Year( WorkingPeriodStartDate ); SetWorkingPeriod( year.AddYears( offset ) ); break; case TimePeriodMode.Halfyear: Halfyear halfyear = new Halfyear( WorkingPeriodStartDate ); SetWorkingPeriod( halfyear.AddHalfyears( offset ) ); break; case TimePeriodMode.Quarter: Quarter quarter = new Quarter( WorkingPeriodStartDate ); SetWorkingPeriod( quarter.AddQuarters( offset ) ); break; case TimePeriodMode.Month: Month month = new Month( WorkingPeriodStartDate ); SetWorkingPeriod( month.AddMonths( offset ) ); break; case TimePeriodMode.Week: Week week = new Week( WorkingPeriodStartDate ); SetWorkingPeriod( week.AddWeeks( offset ) ); break; case TimePeriodMode.Day: Day day = new Day( WorkingPeriodStartDate ); SetWorkingPeriod( day.AddDays( offset ) ); break; } }