public void CalendarGetGapTest() { // simmulation of some reservations var periods = new TimePeriodCollection { new DayRangeCollection(2011, 3, 7, 2), new DayRangeCollection(2011, 3, 16, 2) }; // the overall search range var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1); // limits의 내부이고, 주말인 DayRange를 추가합니다. var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd()); periods.AddAll(excludeDays.Cast <ITimePeriod>()); var gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar()); var gaps = gapCalculator.GetGaps(periods, limits); gaps.Count.Should().Be(4); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True(); gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True(); gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True(); gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True(); }
public void CalendarGetGapTest() { // simmulation of some reservations TimePeriodCollection periods = new TimePeriodCollection(); periods.Add(new Days(2011, 3, 7, 2)); periods.Add(new Days(2011, 3, 16, 2)); // the overall search range CalendarTimeRange limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); Days days = new Days(limits.Start, limits.Duration.Days + 1); ITimePeriodCollection dayList = days.GetDays(); foreach (Day day in dayList) { if (!limits.HasInside(day)) { continue; // outside of the search scope } if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday) { periods.Add(day); // // exclude weekend day } } TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(new TimeCalendar()); ITimePeriodCollection gaps = gapCalculator.GetGaps(periods, limits); Assert.Equal(4, gaps.Count); Assert.True(gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), Duration.Days(1)))); Assert.True(gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), Duration.Days(3)))); Assert.True(gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), Duration.Days(2)))); Assert.True(gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), Duration.Days(1)))); } // CalendarGetGapTest
public void CalendarGetGapTest() { // simmulation of some reservations var periods = new TimePeriodCollection { new DayRangeCollection(2011, 3, 7, 2), new DayRangeCollection(2011, 3, 16, 2) }; // the overall search range var limits = new CalendarTimeRange(new DateTime(2011, 3, 4), new DateTime(2011, 3, 21)); var days = new DayRangeCollection(limits.Start, limits.Duration.Days + 1); // limits의 내부이고, 주말인 DayRange를 추가합니다. var excludeDays = days.GetDays().Where(day => limits.HasInside(day) && day.DayOfWeek.IsWeekEnd()); periods.AddAll(excludeDays.Cast<ITimePeriod>()); var gapCalculator = new TimeGapCalculator<TimeRange>(new TimeCalendar()); var gaps = gapCalculator.GetGaps(periods, limits); gaps.Count.Should().Be(4); gaps[0].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 4), DurationUtil.Days(1))).Should().Be.True(); gaps[1].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 9), DurationUtil.Days(3))).Should().Be.True(); gaps[2].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 14), DurationUtil.Days(2))).Should().Be.True(); gaps[3].IsSamePeriod(new TimeRange(new DateTime(2011, 3, 18), DurationUtil.Days(1))).Should().Be.True(); }