Пример #1
0
        public JsonResult Availabilities(int hotelId, IEnumerable<int> roomTypeIds, DateTime start, DateTime end, DateTime? startTime, DateTime? endTime, IEnumerable<Query> queries)
        {
            var startDT = start.MergeTime(startTime);
            var endDT = end.MergeTime(endTime);
            var manager = this.GetManagerFor<IRoomBookingManager>();
            var results = manager.Search(hotelId, roomTypeIds, startDT, endDT).ToList();

            var periods = new TimeRange(startDT, endDT, true);
            var collector = new CalendarPeriodCollector(new CalendarPeriodCollectorFilter(), periods);
            collector.CollectDays();
            var days = collector.Periods.Select(d => d.Start).ToList();
            days.Add(endDT);
            days.Insert(0, startDT);

            var tManager = this.GetManagerFor<IRoomTypeManager>();
            var roomTypes = tManager.GetByIds(roomTypeIds).ToList();

            var resultDTOs = results.Select(t => new RoomBookingDTO(queries, t));

            var json = new AvailabilityResultDTO
            {
                DTSlots = days,
                RoomTypes = roomTypes.Select(t => new RoomTypeDTO
                {
                    Id = t.Id,
                    Name = t.Name,
                    Rooms = t.Rooms.Where(r => r.HotelId == hotelId).Select(r => new RoomDTO(r)).ToList()
                }).ToList(),
                Bookings = resultDTOs
            };

            return Json(json);
        }
        public void CollectDaysTest() {
            var filter = new CalendarPeriodCollectorFilter();

            //! 1월의 금요일만 추출
            filter.Months.Add(January);
            filter.WeekDays.Add(DayOfWeek.Friday);

            var testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            var collector = new CalendarPeriodCollector(filter, testPeriod);
            collector.CollectDays();

            if(IsDebugEnabled) {
                foreach(var period in collector.Periods)
                    log.Debug("CollectDays... Period=" + period);
            }

            collector.Periods.Count.Should().Be(9);

            collector.Periods[0].IsSamePeriod(new DayRange(new DateTime(2010, 1, 1))).Should().Be.True();
            collector.Periods[1].IsSamePeriod(new DayRange(new DateTime(2010, 1, 8))).Should().Be.True();
            collector.Periods[2].IsSamePeriod(new DayRange(new DateTime(2010, 1, 15))).Should().Be.True();
            collector.Periods[3].IsSamePeriod(new DayRange(new DateTime(2010, 1, 22))).Should().Be.True();
            collector.Periods[4].IsSamePeriod(new DayRange(new DateTime(2010, 1, 29))).Should().Be.True();

            collector.Periods[5].IsSamePeriod(new DayRange(new DateTime(2011, 1, 7))).Should().Be.True();
            collector.Periods[6].IsSamePeriod(new DayRange(new DateTime(2011, 1, 14))).Should().Be.True();
            collector.Periods[7].IsSamePeriod(new DayRange(new DateTime(2011, 1, 21))).Should().Be.True();
            collector.Periods[8].IsSamePeriod(new DayRange(new DateTime(2011, 1, 28))).Should().Be.True();
        }
        public void CollectExcludePeriodTest()
        {
            const int workingDays2011 = 365 - 2 - ( 51 * 2 ) - 1;
            const int workingDaysMarch2011 = 31 - 8; // total days - weekend days

            Year year2011 = new Year( 2011 );

            CalendarPeriodCollectorFilter filter1 = new CalendarPeriodCollectorFilter();
            filter1.AddWorkingWeekDays();
            CalendarPeriodCollector collector1 = new CalendarPeriodCollector( filter1, year2011 );
            collector1.CollectDays();
            Assert.AreEqual( collector1.Periods.Count, workingDays2011 );

            // exclude month
            CalendarPeriodCollectorFilter filter2 = new CalendarPeriodCollectorFilter();
            filter2.AddWorkingWeekDays();
            filter2.ExcludePeriods.Add( new Month( 2011, YearMonth.March ) );
            CalendarPeriodCollector collector2 = new CalendarPeriodCollector( filter2, year2011 );
            collector2.CollectDays();
            Assert.AreEqual( collector2.Periods.Count, workingDays2011 - workingDaysMarch2011 );

            // exclude weeks (holidays)
            CalendarPeriodCollectorFilter filter3 = new CalendarPeriodCollectorFilter();
            filter3.AddWorkingWeekDays();
            filter3.ExcludePeriods.Add( new Month( 2011, YearMonth.March ) );
            filter3.ExcludePeriods.Add( new Weeks( 2011, 26, 2 ) );
            CalendarPeriodCollector collector3 = new CalendarPeriodCollector( filter3, year2011 );
            collector3.CollectDays();
            Assert.AreEqual( collector3.Periods.Count, workingDays2011 - workingDaysMarch2011 - 10 );
        }
Пример #4
0
        public JsonResult Availabilities(int hotelId, IEnumerable <int> roomTypeIds, DateTime start, DateTime end, DateTime?startTime, DateTime?endTime, IEnumerable <Query> queries)
        {
            var startDT = start.MergeTime(startTime);
            var endDT   = end.MergeTime(endTime);
            var manager = this.GetManagerFor <IRoomBookingManager>();
            var results = manager.Search(hotelId, roomTypeIds, startDT, endDT).ToList();

            var periods   = new TimeRange(startDT, endDT, true);
            var collector = new CalendarPeriodCollector(new CalendarPeriodCollectorFilter(), periods);

            collector.CollectDays();
            var days = collector.Periods.Select(d => d.Start).ToList();

            days.Add(endDT);
            days.Insert(0, startDT);

            var tManager  = this.GetManagerFor <IRoomTypeManager>();
            var roomTypes = tManager.GetByIds(roomTypeIds).ToList();

            var resultDTOs = results.Select(t => new RoomBookingDTO(queries, t));

            var json = new AvailabilityResultDTO
            {
                DTSlots   = days,
                RoomTypes = roomTypes.Select(t => new RoomTypeDTO
                {
                    Id    = t.Id,
                    Name  = t.Name,
                    Rooms = t.Rooms.Where(r => r.HotelId == hotelId).Select(r => new RoomDTO(r)).ToList()
                }).ToList(),
                Bookings = resultDTOs
            };

            return(Json(json));
        }
Пример #5
0
        public static double NetworkDays(DateTime start, DateTime end,
                                         IEnumerable <DateTime> holidays      = null,
                                         ITimePeriodCollection holidayPeriods = null)
        {
            var startDay = new Day(start < end ? start : end);
            var endDay   = new Day(end > start ? end : start);

            if (startDay.Equals(endDay))
            {
                return(0);
            }

            var filter = new CalendarPeriodCollectorFilter();

            filter.AddWorkingWeekDays();
            if (holidays != null)
            {
                foreach (DateTime holiday in holidays)
                {
                    filter.ExcludePeriods.Add(new Day(holiday));
                }
            }
            if (holidayPeriods != null)
            {
                filter.ExcludePeriods.AddAll(holidayPeriods);
            }

            var testPeriod = new CalendarTimeRange(start, end);
            var collector  = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectDays();

            var networkDays = 0.0d;

            foreach (ICalendarTimeRange period in collector.Periods)
            {
                networkDays += Math.Round(period.Duration.TotalDays, 2);
            }
            return(networkDays);
        }
        public void CollectDaysTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();
            filter.Months.Add( YearMonth.January );
            filter.WeekDays.Add( DayOfWeek.Friday );

            CalendarTimeRange testPeriod = new CalendarTimeRange( new DateTime( 2010, 1, 1 ), new DateTime( 2011, 12, 31 ) );

            CalendarPeriodCollector collector = new CalendarPeriodCollector( filter, testPeriod );
            collector.CollectDays();

            Assert.AreEqual( collector.Periods.Count, 9 );
            Assert.IsTrue( collector.Periods[ 0 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2010, 1, 01 ), new DateTime( 2010, 1, 02 ) ) ) );
            Assert.IsTrue( collector.Periods[ 1 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2010, 1, 08 ), new DateTime( 2010, 1, 09 ) ) ) );
            Assert.IsTrue( collector.Periods[ 2 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2010, 1, 15 ), new DateTime( 2010, 1, 16 ) ) ) );
            Assert.IsTrue( collector.Periods[ 3 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2010, 1, 22 ), new DateTime( 2010, 1, 23 ) ) ) );
            Assert.IsTrue( collector.Periods[ 4 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2010, 1, 29 ), new DateTime( 2010, 1, 30 ) ) ) );
            Assert.IsTrue( collector.Periods[ 5 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2011, 1, 07 ), new DateTime( 2011, 1, 08 ) ) ) );
            Assert.IsTrue( collector.Periods[ 6 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2011, 1, 14 ), new DateTime( 2011, 1, 15 ) ) ) );
            Assert.IsTrue( collector.Periods[ 7 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2011, 1, 21 ), new DateTime( 2011, 1, 22 ) ) ) );
            Assert.IsTrue( collector.Periods[ 8 ].IsSamePeriod( new CalendarTimeRange( new DateTime( 2011, 1, 28 ), new DateTime( 2011, 1, 29 ) ) ) );
        }
        public void CollectDaysTest()
        {
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();

            filter.Months.Add(YearMonth.January);
            filter.WeekDays.Add(DayOfWeek.Friday);

            CalendarTimeRange testPeriod = new CalendarTimeRange(new DateTime(2010, 1, 1), new DateTime(2011, 12, 31));

            CalendarPeriodCollector collector = new CalendarPeriodCollector(filter, testPeriod);

            collector.CollectDays();

            Assert.AreEqual(collector.Periods.Count, 9);
            Assert.IsTrue(collector.Periods[0].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 01), new DateTime(2010, 1, 02))));
            Assert.IsTrue(collector.Periods[1].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 08), new DateTime(2010, 1, 09))));
            Assert.IsTrue(collector.Periods[2].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 15), new DateTime(2010, 1, 16))));
            Assert.IsTrue(collector.Periods[3].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 22), new DateTime(2010, 1, 23))));
            Assert.IsTrue(collector.Periods[4].IsSamePeriod(new CalendarTimeRange(new DateTime(2010, 1, 29), new DateTime(2010, 1, 30))));
            Assert.IsTrue(collector.Periods[5].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 07), new DateTime(2011, 1, 08))));
            Assert.IsTrue(collector.Periods[6].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 14), new DateTime(2011, 1, 15))));
            Assert.IsTrue(collector.Periods[7].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 21), new DateTime(2011, 1, 22))));
            Assert.IsTrue(collector.Periods[8].IsSamePeriod(new CalendarTimeRange(new DateTime(2011, 1, 28), new DateTime(2011, 1, 29))));
        }         // CollectDaysTest
        public void CollectExcludePeriodTest()
        {
            const int workingDays2011      = 365 - 2 - (51 * 2) - 1;
            const int workingDaysMarch2011 = 31 - 8;             // total days - weekend days

            Year year2011 = new Year(2011);

            CalendarPeriodCollectorFilter filter1 = new CalendarPeriodCollectorFilter();

            filter1.AddWorkingWeekDays();
            CalendarPeriodCollector collector1 = new CalendarPeriodCollector(filter1, year2011);

            collector1.CollectDays();
            Assert.AreEqual(collector1.Periods.Count, workingDays2011);

            // exclude month
            CalendarPeriodCollectorFilter filter2 = new CalendarPeriodCollectorFilter();

            filter2.AddWorkingWeekDays();
            filter2.ExcludePeriods.Add(new Month(2011, YearMonth.March));
            CalendarPeriodCollector collector2 = new CalendarPeriodCollector(filter2, year2011);

            collector2.CollectDays();
            Assert.AreEqual(collector2.Periods.Count, workingDays2011 - workingDaysMarch2011);

            // exclude weeks (holidays)
            CalendarPeriodCollectorFilter filter3 = new CalendarPeriodCollectorFilter();

            filter3.AddWorkingWeekDays();
            filter3.ExcludePeriods.Add(new Month(2011, YearMonth.March));
            filter3.ExcludePeriods.Add(new Weeks(2011, 26, 2));
            CalendarPeriodCollector collector3 = new CalendarPeriodCollector(filter3, year2011);

            collector3.CollectDays();
            Assert.AreEqual(collector3.Periods.Count, workingDays2011 - workingDaysMarch2011 - 10);
        } // CollectExcludePeriodTest
        public void CollectExcludePeriodTest() {
            const int workingDays2011 = 365 - 2 - (51 * 2) - 1;
            const int workingDaysMarch2011 = 31 - 8; // total days - weekend days

            var year2011 = new YearRange(2011);

            var filter1 = new CalendarPeriodCollectorFilter();
            filter1.AddWorkingWeekDays();

            var collector1 = new CalendarPeriodCollector(filter1, year2011);
            collector1.CollectDays();
            collector1.Periods.Count.Should().Be(workingDays2011);

            // 3월 제외
            var filter2 = new CalendarPeriodCollectorFilter();
            filter2.AddWorkingWeekDays();
            filter2.ExcludePeriods.Add(new MonthRange(2011, March));

            var collector2 = new CalendarPeriodCollector(filter2, year2011);
            collector2.CollectDays();
            collector2.Periods.Count.Should().Be(workingDays2011 - workingDaysMarch2011);


            // 2011년 26주차~27주차 (여름휴가가 2주야!!!)
            //
            var filter3 = new CalendarPeriodCollectorFilter();
            filter3.AddWorkingWeekDays();
            filter3.ExcludePeriods.Add(new MonthRange(2011, March));
            filter3.ExcludePeriods.Add(new WeekRangeCollection(2011, 26, 2));

            var collector3 = new CalendarPeriodCollector(filter3, year2011);
            collector3.CollectDays();
            collector3.Periods.Count.Should().Be(workingDays2011 - workingDaysMarch2011 - 2 * TimeSpec.WeekDaysPerWeek);
        }
Пример #10
0
        // ----------------------------------------------------------------------
        public double NetworkDays( DateTime start, DateTime end, IEnumerable<DateTime> holidays = null, ITimePeriodCollection holidayPeriods = null )
        {
            Day startDay = new Day( start < end ? start : end );
            Day endDay = new Day( end > start ? end : start );
            if ( startDay.Equals( endDay ) )
            {
                return 0;
            }

            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();
            filter.AddWorkingWeekDays(); // only working days
            if ( holidays != null )
            {
                foreach ( DateTime holiday in holidays )
                {
                    filter.ExcludePeriods.Add( new Day( holiday ) );
                }
            }
            if ( holidayPeriods != null )
            {
                filter.ExcludePeriods.AddAll( holidayPeriods );
            }

            CalendarTimeRange testPeriod = new CalendarTimeRange( start, end );
            CalendarPeriodCollector collector = new CalendarPeriodCollector( filter, testPeriod );
            collector.CollectDays();

            double networkDays = 0.0;
            foreach ( ICalendarTimeRange period in collector.Periods )
            {
                networkDays += Math.Round( period.Duration.TotalDays, 2 );
            }
            return networkDays;
        }
Пример #11
0
        public void FindRemainigYearFridaysSample()
        {
            // filter: only Fridays
            CalendarPeriodCollectorFilter filter = new CalendarPeriodCollectorFilter();
            filter.WeekDays.Add( DayOfWeek.Friday );

            // the collecting period
            CalendarTimeRange collectPeriod = new CalendarTimeRange( DateTime.Now, new Year().End.Date );

            // collect all Fridays
            CalendarPeriodCollector collector = new CalendarPeriodCollector( filter, collectPeriod );
            collector.CollectDays();

            // show the results
            foreach ( ITimePeriod period in collector.Periods )
            {
                Console.WriteLine( "Friday: " + period );
            }
        }