public void GetPeriodsOfTest() { Parallel.ForEach(Enum.GetValues(typeof(PeriodKind)).Cast <PeriodKind>(), periodKind => { if (periodKind == PeriodKind.Unknown) { return; } if (periodKind == PeriodKind.Millisecond) { return; } for (int count = 1; count < 5; count++) { var moment = startTime; var timeCalendar = TimeCalendar.NewEmptyOffset(); var period = TimeTool.GetPeriodsOf(moment, periodKind, count, timeCalendar); period.HasPeriod.Should().Be.True(); period.HasInside(moment).Should().Be.True(); period.HasInside(endTime).Should().Be.False(); if (IsDebugEnabled) { log.Debug("[{0}] : Periods [{1}] HasInside([{2}])", periodKind, period, moment); } } }); }
public void GetPeriodOfWithCalendarTest() { foreach (PeriodKind periodKind in Enum.GetValues(typeof(PeriodKind))) { if (periodKind == PeriodKind.Unknown) { continue; } if (periodKind == PeriodKind.Millisecond) { continue; } var moment = startTime; var timeCalendar = TimeCalendar.NewEmptyOffset(); var period = TimeTool.GetPeriodOf(moment, periodKind, timeCalendar); period.HasInside(moment).Should().Be.True(); period.HasInside(endTime).Should().Be.False(); if (IsDebugEnabled) { log.Debug("[{0}] : Period[{1}] HasInside([{2}])", periodKind, period, moment); } } }
public void CalendarHalfyearTest() { var currentYear = ClockProxy.Clock.Now.Year; var calendar = TimeCalendar.NewEmptyOffset(); var h1 = new HalfyearRange(currentYear, HalfyearKind.First, calendar); Assert.IsTrue(h1.IsReadOnly); Assert.IsTrue(h1.IsCalendarHalfyear); h1.YearBaseMonth.Should().Be(TimeSpec.CalendarYearStartMonth); h1.Halfyear.Should().Be(HalfyearKind.First); h1.BaseYear.Should().Be(currentYear); h1.Start.Should().Be(new DateTime(currentYear, 1, 1)); h1.End.Should().Be(new DateTime(currentYear, 7, 1)); var h2 = new HalfyearRange(currentYear, HalfyearKind.Second, calendar); Assert.IsTrue(h2.IsReadOnly); Assert.IsTrue(h2.IsCalendarHalfyear); h2.YearBaseMonth.Should().Be(TimeSpec.CalendarYearStartMonth); h2.Halfyear.Should().Be(HalfyearKind.Second); h2.BaseYear.Should().Be(currentYear); h2.Start.Should().Be(new DateTime(currentYear, 7, 1)); h2.End.Should().Be(new DateTime(currentYear + 1, 1, 1)); }
public void GetWeekRangeTest() { var weekRange = TimeTool.GetWeekRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfWeek(); weekRange.Start.Should().Be(start); weekRange.End.Should().Be(weekRange.GetNextWeek().Start); }
public void GetMinuteRangeTest() { var minuteRange = TimeTool.GetMinuteRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfMinute(); minuteRange.Start.Should().Be(start); minuteRange.End.Should().Be(minuteRange.GetNextMinute().Start); }
public void GetHourRangeTest() { var hourRange = TimeTool.GetHourRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfHour(); hourRange.Start.Should().Be(start); hourRange.End.Should().Be(hourRange.GetNextHour().Start); }
public void GetDayRangeTest() { var dayRange = TimeTool.GetDayRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfDay(); dayRange.Start.Should().Be(start); dayRange.End.Should().Be(dayRange.GetNextDay().Start); }
public void GetQuarterRangeTest() { var quarterRange = TimeTool.GetQuarterRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfQuarter(); quarterRange.Start.Should().Be(start); quarterRange.End.Should().Be(quarterRange.GetNextQuarter().Start); }
public void InitValuesTest() { var now = ClockProxy.Clock.Now; var firstDay = new DateTime(now.Year, now.Month, now.Day); var secondDay = firstDay.AddDays(1); var day = new DayRange(now, TimeCalendar.NewEmptyOffset()); day.Start.Should().Be(firstDay); day.End.Should().Be(secondDay); }
public void MinuteTest() { var now = ClockProxy.Clock.Now; var firstMinute = now.TrimToSecond(); var secondMinute = firstMinute.AddMinutes(1); var m = new MinuteRange(now, TimeCalendar.NewEmptyOffset()); m.Start.Should().Be(firstMinute); m.End.Should().Be(secondMinute); }
public void AddHalfyearsTest() { const int yearStartMonth = April; var currentYear = ClockProxy.Clock.Now.Year; var timeCalendar = TimeCalendar.NewEmptyOffset(yearStartMonth); var calendarStartDate = new DateTime(currentYear, 4, 1); var calendarHalfyear = new HalfyearRange(currentYear, HalfyearKind.First, timeCalendar); calendarHalfyear.AddHalfyears(0).Should().Be(calendarHalfyear); var prevH1 = calendarHalfyear.AddHalfyears(-1); prevH1.Halfyear.Should().Be(HalfyearKind.Second); prevH1.BaseYear.Should().Be(currentYear - 1); prevH1.Start.Should().Be(calendarStartDate.AddMonths(-6)); prevH1.End.Should().Be(calendarStartDate); var prevH2 = calendarHalfyear.AddHalfyears(-2); prevH2.Halfyear.Should().Be(HalfyearKind.First); prevH2.BaseYear.Should().Be(currentYear - 1); prevH2.Start.Should().Be(calendarStartDate.AddMonths(-12)); prevH2.End.Should().Be(calendarStartDate.AddMonths(-6)); var prevH3 = calendarHalfyear.AddHalfyears(-3); prevH3.Halfyear.Should().Be(HalfyearKind.Second); prevH3.BaseYear.Should().Be(currentYear - 2); prevH3.Start.Should().Be(calendarStartDate.AddMonths(-18)); prevH3.End.Should().Be(calendarStartDate.AddMonths(-12)); var futureH1 = calendarHalfyear.AddHalfyears(1); futureH1.Halfyear.Should().Be(HalfyearKind.Second); futureH1.BaseYear.Should().Be(currentYear); futureH1.Start.Should().Be(calendarStartDate.AddMonths(6)); futureH1.End.Should().Be(calendarStartDate.AddMonths(12)); var futureH2 = calendarHalfyear.AddHalfyears(2); futureH2.Halfyear.Should().Be(HalfyearKind.First); futureH2.BaseYear.Should().Be(currentYear + 1); futureH2.Start.Should().Be(calendarStartDate.AddMonths(12)); futureH2.End.Should().Be(calendarStartDate.AddMonths(18)); var futureH3 = calendarHalfyear.AddHalfyears(3); futureH3.Halfyear.Should().Be(HalfyearKind.Second); futureH3.BaseYear.Should().Be(currentYear + 1); futureH3.Start.Should().Be(calendarStartDate.AddMonths(18)); futureH3.End.Should().Be(calendarStartDate.AddMonths(24)); }
public void GetYearRangeTest() { var yearRange = TimeTool.GetYearRange(startTime, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfYear(); yearRange.Start.Should().Be(start); yearRange.StartYear.Should().Be(start.Year); yearRange.End.Should().Be(start.AddYears(1)); yearRange.EndYear.Should().Be(start.AddYears(1).Year); }
public void InitValuesTest() { var now = ClockProxy.Clock.Now; var firstMonth = new DateTime(now.Year, now.Month, 1); var secondMonth = firstMonth.AddMonths(1); var month = new MonthRange(now.Year, now.Month, TimeCalendar.NewEmptyOffset()); month.Start.Should().Be(firstMonth); month.End.Should().Be(secondMonth); }
public void AddDaysTest() { var now = ClockProxy.Clock.Now; var nowDate = now.Date; var day = new DayRange(now, TimeCalendar.NewEmptyOffset()); day.AddDays(0).Should().Be(day); Enumerable .Range(-60, 120) .RunEach(i => day.AddDays(i).Start.Should().Be(nowDate.AddDays(i))); }
public void AddMinutes() { var now = ClockProxy.Clock.Now; var m = new MinuteRange(now, TimeCalendar.NewEmptyOffset()); var minuteTime = now.TrimToSecond(); m.AddMinutes(-1).Start.Should().Be(minuteTime.AddMinutes(-1)); m.AddMinutes(1).Start.Should().Be(minuteTime.AddMinutes(1)); Enumerable .Range(-TimeSpec.MinutesPerHour * 2, TimeSpec.MinutesPerHour * 2) .RunEach(i => m.AddMinutes(i).Start.Should().Be(minuteTime.AddMinutes(i))); }
public void GetMinuteRangesTest() { Enumerable .Range(1, PeriodCount) .RunEach(i => { var hourRanges = TimeTool.GetMinuteRanges(startTime, i, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfMinute(); hourRanges.Start.Should().Be(start); hourRanges.End.Should().Be(start.AddMinutes(i)); hourRanges.MinuteCount.Should().Be(i); }); }
public void GetDayRangesTest() { Enumerable .Range(1, PeriodCount) .RunEach(i => { var dayRanges = TimeTool.GetDayRanges(startTime, i, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfDay(); dayRanges.Start.Should().Be(start); dayRanges.End.Should().Be(start.AddDays(i)); dayRanges.DayCount.Should().Be(i); }); }
public void GetWeekRangesTest() { Enumerable .Range(1, PeriodCount) .RunEach(i => { var weekRanges = TimeTool.GetWeekRanges(startTime, i, TimeCalendar.NewEmptyOffset()); var start = TimeTool.StartTimeOfWeek(startTime); weekRanges.Start.Should().Be(start); weekRanges.End.Should().Be(start.AddDays(i * TimeSpec.DaysPerWeek)); weekRanges.WeekCount.Should().Be(i); }); }
public void GetQuarterRangesTest() { Enumerable .Range(1, PeriodCount) .RunEach(i => { var quarterRanges = TimeTool.GetQuarterRanges(startTime, i, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfQuarter(); quarterRanges.Start.Should().Be(start); quarterRanges.End.Should().Be(start.AddMonths(i * TimeSpec.MonthsPerQuarter)); quarterRanges.QuarterCount.Should().Be(i); }); }
public void GetYearRangesTest() { Enumerable .Range(1, PeriodCount) .RunEach(i => { var yearRanges = TimeTool.GetYearRanges(startTime, i, TimeCalendar.NewEmptyOffset()); var start = startTime.StartTimeOfYear(); yearRanges.Start.Should().Be(start); yearRanges.StartYear.Should().Be(start.Year); yearRanges.End.Should().Be(start.AddYears(i)); yearRanges.EndYear.Should().Be(start.AddYears(i).Year); yearRanges.YearCount.Should().Be(i); }); }
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.Equal(day.AddDays(0), day); DateTime previousDay = nowDay.AddDays(-1); Assert.Equal(day.AddDays(-1).Year, previousDay.Year); Assert.Equal(day.AddDays(-1).Month, previousDay.Month); Assert.Equal(day.AddDays(-1).DayValue, previousDay.Day); DateTime nextDay = nowDay.AddDays(1); Assert.Equal(day.AddDays(1).Year, nextDay.Year); Assert.Equal(day.AddDays(1).Month, nextDay.Month); Assert.Equal(day.AddDays(1).DayValue, nextDay.Day); } // AddDaysTest
public void CalendarYearQuarterTest() { var currentYear = ClockProxy.Clock.Now.Year; var timeCalendar = TimeCalendar.NewEmptyOffset(); var current = new QuarterRange(currentYear, QuarterKind.First); current.GetNextQuarter().GetNextQuarter().GetNextQuarter().GetNextQuarter().Quarter.Should().Be(current.Quarter); current.GetPreviousQuarter().GetPreviousQuarter().GetPreviousQuarter().GetPreviousQuarter().Quarter.Should().Be( current.Quarter); var q1 = new QuarterRange(currentYear, QuarterKind.First, timeCalendar); Assert.IsTrue(q1.IsReadOnly); q1.Quarter.Should().Be(QuarterKind.First); q1.Start.Should().Be(new DateTime(currentYear, TimeSpec.FirstQuarterMonth, 1)); q1.End.Should().Be(new DateTime(currentYear, TimeSpec.SecondQuarterMonth, 1)); var q2 = new QuarterRange(currentYear, QuarterKind.Second, timeCalendar); Assert.IsTrue(q2.IsReadOnly); q2.Quarter.Should().Be(QuarterKind.Second); q2.Start.Should().Be(new DateTime(currentYear, TimeSpec.SecondQuarterMonth, 1)); q2.End.Should().Be(new DateTime(currentYear, TimeSpec.ThirdQuarterMonth, 1)); var q3 = new QuarterRange(currentYear, QuarterKind.Third, timeCalendar); Assert.IsTrue(q3.IsReadOnly); q3.Quarter.Should().Be(QuarterKind.Third); q3.Start.Should().Be(new DateTime(currentYear, TimeSpec.ThirdQuarterMonth, 1)); q3.End.Should().Be(new DateTime(currentYear, TimeSpec.FourthQuarterMonth, 1)); var q4 = new QuarterRange(currentYear, QuarterKind.Fourth, timeCalendar); Assert.IsTrue(q4.IsReadOnly); q4.Quarter.Should().Be(QuarterKind.Fourth); q4.Start.Should().Be(new DateTime(currentYear, TimeSpec.FourthQuarterMonth, 1)); q4.End.Should().Be(new DateTime(currentYear + 1, TimeSpec.FirstQuarterMonth, 1)); }
public void AddHoursTest() { var now = ClockProxy.Clock.Now; var nowHour = now.TrimToMinute(); var hourRange = new HourRange(now, TimeCalendar.NewEmptyOffset()); hourRange.AddHours(0).Should().Be(hourRange); var previousHour = nowHour.AddHours(-1); hourRange.AddHours(-1).Year.Should().Be(previousHour.Year); hourRange.AddHours(-1).Month.Should().Be(previousHour.Month); hourRange.AddHours(-1).Day.Should().Be(previousHour.Day); hourRange.AddHours(-1).Hour.Should().Be(previousHour.Hour); var nextHour = nowHour.AddHours(1); hourRange.AddHours(1).Year.Should().Be(nextHour.Year); hourRange.AddHours(1).Month.Should().Be(nextHour.Month); hourRange.AddHours(1).Day.Should().Be(nextHour.Day); hourRange.AddHours(1).Hour.Should().Be(nextHour.Hour); }
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime thisYear = new DateTime(now.Year, 1, 1); DateTime nextYear = thisYear.AddYears(1); Year year = new Year(now, TimeCalendar.NewEmptyOffset()); Assert.AreEqual(year.Start.Year, thisYear.Year); Assert.AreEqual(year.Start.Month, thisYear.Month); Assert.AreEqual(year.Start.Day, thisYear.Day); Assert.AreEqual(year.Start.Hour, 0); Assert.AreEqual(year.Start.Minute, 0); Assert.AreEqual(year.Start.Second, 0); Assert.AreEqual(year.Start.Millisecond, 0); Assert.AreEqual(year.End.Year, nextYear.Year); Assert.AreEqual(year.End.Month, nextYear.Month); Assert.AreEqual(year.End.Day, nextYear.Day); Assert.AreEqual(year.End.Hour, 0); Assert.AreEqual(year.End.Minute, 0); Assert.AreEqual(year.End.Second, 0); Assert.AreEqual(year.End.Millisecond, 0); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstMonth = new DateTime(now.Year, now.Month, 1); DateTime secondMonth = firstMonth.AddMonths(1); Month month = new Month(now.Year, (YearMonth)now.Month, TimeCalendar.NewEmptyOffset()); Assert.Equal(month.Start.Year, firstMonth.Year); Assert.Equal(month.Start.Month, firstMonth.Month); Assert.Equal(month.Start.Day, firstMonth.Day); Assert.Equal(0, month.Start.Hour); Assert.Equal(0, month.Start.Minute); Assert.Equal(0, month.Start.Second); Assert.Equal(0, month.Start.Millisecond); Assert.Equal(month.End.Year, secondMonth.Year); Assert.Equal(month.End.Month, secondMonth.Month); Assert.Equal(month.End.Day, secondMonth.Day); Assert.Equal(0, month.End.Hour); Assert.Equal(0, month.End.Minute); Assert.Equal(0, month.End.Second); Assert.Equal(0, month.End.Millisecond); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstHour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0); DateTime secondHour = firstHour.AddHours(1); Hour hour = new Hour(now, TimeCalendar.NewEmptyOffset()); Assert.AreEqual(hour.Start.Year, firstHour.Year); Assert.AreEqual(hour.Start.Month, firstHour.Month); Assert.AreEqual(hour.Start.Day, firstHour.Day); Assert.AreEqual(hour.Start.Hour, firstHour.Hour); Assert.AreEqual(hour.Start.Minute, 0); Assert.AreEqual(hour.Start.Second, 0); Assert.AreEqual(hour.Start.Millisecond, 0); Assert.AreEqual(hour.End.Year, secondHour.Year); Assert.AreEqual(hour.End.Month, secondHour.Month); Assert.AreEqual(hour.End.Day, secondHour.Day); Assert.AreEqual(hour.End.Hour, secondHour.Hour); Assert.AreEqual(hour.End.Minute, 0); Assert.AreEqual(hour.End.Second, 0); Assert.AreEqual(hour.End.Millisecond, 0); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstMinute = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0); DateTime secondMinute = firstMinute.AddMinutes(1); Minute minute = new Minute(now, TimeCalendar.NewEmptyOffset()); Assert.AreEqual(minute.Start.Year, firstMinute.Year); Assert.AreEqual(minute.Start.Month, firstMinute.Month); Assert.AreEqual(minute.Start.Day, firstMinute.Day); Assert.AreEqual(minute.Start.Hour, firstMinute.Hour); Assert.AreEqual(minute.Start.Minute, firstMinute.Minute); Assert.AreEqual(minute.Start.Second, 0); Assert.AreEqual(minute.Start.Millisecond, 0); Assert.AreEqual(minute.End.Year, secondMinute.Year); Assert.AreEqual(minute.End.Month, secondMinute.Month); Assert.AreEqual(minute.End.Day, secondMinute.Day); Assert.AreEqual(minute.End.Hour, secondMinute.Hour); Assert.AreEqual(minute.End.Minute, secondMinute.Minute); Assert.AreEqual(minute.End.Second, 0); Assert.AreEqual(minute.End.Millisecond, 0); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstHalfyear = new DateTime(now.Year, 1, 1); DateTime secondHalfyear = new DateTime(now.Year, 7, 1); Halfyear halfyear = new Halfyear(now.Year, YearHalfyear.First, TimeCalendar.NewEmptyOffset()); Assert.Equal(halfyear.Start.Year, firstHalfyear.Year); Assert.Equal(halfyear.Start.Month, firstHalfyear.Month); Assert.Equal(halfyear.Start.Day, firstHalfyear.Day); Assert.Equal(0, halfyear.Start.Hour); Assert.Equal(0, halfyear.Start.Minute); Assert.Equal(0, halfyear.Start.Second); Assert.Equal(0, halfyear.Start.Millisecond); Assert.Equal(halfyear.End.Year, secondHalfyear.Year); Assert.Equal(halfyear.End.Month, secondHalfyear.Month); Assert.Equal(halfyear.End.Day, secondHalfyear.Day); Assert.Equal(0, halfyear.End.Hour); Assert.Equal(0, halfyear.End.Minute); Assert.Equal(0, halfyear.End.Second); Assert.Equal(0, halfyear.End.Millisecond); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstDay = new DateTime(now.Year, now.Month, now.Day); DateTime secondDay = firstDay.AddDays(1); Day day = new Day(now, TimeCalendar.NewEmptyOffset()); Assert.Equal(day.Start.Year, firstDay.Year); Assert.Equal(day.Start.Month, firstDay.Month); Assert.Equal(day.Start.Day, firstDay.Day); Assert.Equal(0, day.Start.Hour); Assert.Equal(0, day.Start.Minute); Assert.Equal(0, day.Start.Second); Assert.Equal(0, day.Start.Millisecond); Assert.Equal(day.End.Year, secondDay.Year); Assert.Equal(day.End.Month, secondDay.Month); Assert.Equal(day.End.Day, secondDay.Day); Assert.Equal(0, day.End.Hour); Assert.Equal(0, day.End.Minute); Assert.Equal(0, day.End.Second); Assert.Equal(0, day.End.Millisecond); } // InitValuesTest
public void InitValuesTest() { DateTime now = ClockProxy.Clock.Now; DateTime firstQuarter = new DateTime(now.Year, 1, 1); DateTime secondQuarter = firstQuarter.AddMonths(TimeSpec.MonthsPerQuarter); Quarter quarter = new Quarter(now.Year, YearQuarter.First, TimeCalendar.NewEmptyOffset()); Assert.Equal(quarter.Start.Year, firstQuarter.Year); Assert.Equal(quarter.Start.Month, firstQuarter.Month); Assert.Equal(quarter.Start.Day, firstQuarter.Day); Assert.Equal(0, quarter.Start.Hour); Assert.Equal(0, quarter.Start.Minute); Assert.Equal(0, quarter.Start.Second); Assert.Equal(0, quarter.Start.Millisecond); Assert.Equal(quarter.End.Year, secondQuarter.Year); Assert.Equal(quarter.End.Month, secondQuarter.Month); Assert.Equal(quarter.End.Day, secondQuarter.Day); Assert.Equal(0, quarter.End.Hour); Assert.Equal(0, quarter.End.Minute); Assert.Equal(0, quarter.End.Second); Assert.Equal(0, quarter.End.Millisecond); } // InitValuesTest