예제 #1
0
        // ----------------------------------------------------------------------
        public void TimePeriodChainSample()
        {
            TimePeriodChain timePeriods = new TimePeriodChain();

            DateTime now     = ClockProxy.Clock.Now;
            DateTime testDay = new DateTime(2010, 7, 23);

            // --- add ---
            timePeriods.Add(new TimeBlock(TimeTrim.Hour(testDay, 8), Duration.Hours(2)));
            timePeriods.Add(new TimeBlock(now, Duration.Hours(1, 30)));
            timePeriods.Add(new TimeBlock(now, Duration.Hour));
            Console.WriteLine("TimePeriodChain.Add(): " + timePeriods);
            // > TimePeriodChain.Add(): Count = 3; 23.07.2010 08:00:00 - 12:30:00 | 0.04:30
            foreach (ITimePeriod timePeriod in timePeriods)
            {
                Console.WriteLine("Item: " + timePeriod);
            }
            // > Item: 23.07.2010 08:00:00 - 10:00:00 | 02:00:00
            // > Item: 23.07.2010 10:00:00 - 11:30:00 | 01:30:00
            // > Item: 23.07.2010 11:30:00 - 12:30:00 | 01:00:00

            // --- insert ---
            timePeriods.Insert(2, new TimeBlock(now, Duration.Minutes(45)));
            Console.WriteLine("TimePeriodChain.Insert(): " + timePeriods);
            // > TimePeriodChain.Insert(): Count = 4; 23.07.2010 08:00:00 - 13:15:00 | 0.05:15
            foreach (ITimePeriod timePeriod in timePeriods)
            {
                Console.WriteLine("Item: " + timePeriod);
            }
            // > Item: 23.07.2010 08:00:00 - 10:00:00 | 02:00:00
            // > Item: 23.07.2010 10:00:00 - 11:30:00 | 01:30:00
            // > Item: 23.07.2010 11:30:00 - 12:15:00 | 00:45:00
            // > Item: 23.07.2010 12:15:00 - 13:15:00 | 01:00:00
        }         // TimePeriodChainSample
예제 #2
0
 public void MinuteTest()
 {
     Assert.Equal(TimeTrim.Minute(testDate), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 0, 0));
     Assert.Equal(TimeTrim.Minute(testDate, 23), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 0));
     Assert.Equal(TimeTrim.Minute(testDate, 23, 55), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 55));
     Assert.Equal(TimeTrim.Minute(testDate, 23, 55, 128), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, 23, 55, 128));
 }         // MinuteTest
        }         // GetNextOffDate

        // ----------------------------------------------------------------------
        private static ScheduleWeek <TimeRange> GetScheduleWeek()
        {
            ScheduleWeek <TimeRange> week = new ScheduleWeek <TimeRange>();

            DateTime now = DateTime.Now;             // used as time container

            week[DayOfWeek.Monday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 6, 30), TimeTrim.Hour(now, 8, 30)));
            week[DayOfWeek.Monday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 15), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Tuesday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 6, 30), TimeTrim.Hour(now, 8, 30)));
            week[DayOfWeek.Monday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 15), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Wednesday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 6, 30), TimeTrim.Hour(now, 8, 30)));
            week[DayOfWeek.Wednesday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 12), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Thursday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 6, 30), TimeTrim.Hour(now, 8, 30)));
            week[DayOfWeek.Thursday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 15), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Friday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 6, 30), TimeTrim.Hour(now, 8, 30)));
            week[DayOfWeek.Friday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 15), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Saturday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 7), TimeTrim.Hour(now, 22, 30)));

            week[DayOfWeek.Sunday].WorkingTimes.Add(new TimeRange(TimeTrim.Hour(now, 7), TimeTrim.Hour(now, 22, 30)));

            return(week);
        }         // GetScheduleWeek
예제 #4
0
 public void HourTest()
 {
     Assert.Equal(TimeTrim.Hour(testDate), new DateTime(testDate.Year, testDate.Month, testDate.Day));
     Assert.Equal(TimeTrim.Hour(testDate, 4), new DateTime(testDate.Year, testDate.Month, testDate.Day, 4, 0, 0));
     Assert.Equal(TimeTrim.Hour(testDate, 4, 23), new DateTime(testDate.Year, testDate.Month, testDate.Day, 4, 23, 0));
     Assert.Equal(TimeTrim.Hour(testDate, 4, 23, 55), new DateTime(testDate.Year, testDate.Month, testDate.Day, 4, 23, 55));
     Assert.Equal(TimeTrim.Hour(testDate, 4, 23, 55, 128), new DateTime(testDate.Year, testDate.Month, testDate.Day, 4, 23, 55, 128));
 }         // HourTest
예제 #5
0
 public void DayTest()
 {
     Assert.Equal(TimeTrim.Day(testDate), new DateTime(testDate.Year, testDate.Month, 1));
     Assert.Equal(TimeTrim.Day(testDate, 5), new DateTime(testDate.Year, testDate.Month, 5, 0, 0, 0));
     Assert.Equal(TimeTrim.Day(testDate, 5, 4), new DateTime(testDate.Year, testDate.Month, 5, 4, 0, 0));
     Assert.Equal(TimeTrim.Day(testDate, 5, 4, 23), new DateTime(testDate.Year, testDate.Month, 5, 4, 23, 0));
     Assert.Equal(TimeTrim.Day(testDate, 5, 4, 23, 55), new DateTime(testDate.Year, testDate.Month, 5, 4, 23, 55));
     Assert.Equal(TimeTrim.Day(testDate, 5, 4, 23, 55, 128), new DateTime(testDate.Year, testDate.Month, 5, 4, 23, 55, 128));
 }         // DayTest
예제 #6
0
 public void MonthTest()
 {
     Assert.Equal(TimeTrim.Month(testDate), new DateTime(testDate.Year, 1, 1));
     Assert.Equal(TimeTrim.Month(testDate, 6), new DateTime(testDate.Year, 6, 1));
     Assert.Equal(TimeTrim.Month(testDate, 6, 5), new DateTime(testDate.Year, 6, 5, 0, 0, 0));
     Assert.Equal(TimeTrim.Month(testDate, 6, 5, 4), new DateTime(testDate.Year, 6, 5, 4, 0, 0));
     Assert.Equal(TimeTrim.Month(testDate, 6, 5, 4, 23), new DateTime(testDate.Year, 6, 5, 4, 23, 0));
     Assert.Equal(TimeTrim.Month(testDate, 6, 5, 4, 23, 55), new DateTime(testDate.Year, 6, 5, 4, 23, 55));
     Assert.Equal(TimeTrim.Month(testDate, 6, 5, 4, 23, 55, 128), new DateTime(testDate.Year, 6, 5, 4, 23, 55, 128));
 }         // MonthTest
예제 #7
0
        }         // TimeRangeSample

        // ----------------------------------------------------------------------
        public bool IsValidReservation(DateTime start, DateTime end)
        {
            if (!TimeCompare.IsSameDay(start, end))
            {
                return(false);                 // multiple day reservation
            }

            TimeRange workingHours = new TimeRange(TimeTrim.Hour(start, 8), TimeTrim.Hour(start, 18));

            return(workingHours.HasInside(new TimeRange(start, end)));
        }         // IsValidReservation
예제 #8
0
        public static bool IsInWorkingHours(TimeBlock block)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            // check Not Saturday or Sunday
            if (block.Start.DayOfWeek == DayOfWeek.Saturday || block.Start.DayOfWeek == DayOfWeek.Sunday)
            {
                return(false);
            }
            TimeRange workingHours = new TimeRange(TimeTrim.Hour(block.Start.Date, int.Parse(db.Administrations.Find(2).Value)), TimeTrim.Hour(block.Start.Date, int.Parse(db.Administrations.Find(3).Value)));

            return(workingHours.HasInside(block));
        }
예제 #9
0
        // ----------------------------------------------------------------------
        public void TimePeriodCollectionSample()
        {
            TimePeriodCollection timePeriods = new TimePeriodCollection();

            DateTime testDay = new DateTime(2010, 7, 23);

            // --- items ---
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 8), TimeTrim.Hour(testDay, 11)));
            timePeriods.Add(new TimeBlock(TimeTrim.Hour(testDay, 10), Duration.Hours(3)));
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 16, 15), TimeTrim.Hour(testDay, 18, 45)));
            timePeriods.Add(new TimeRange(TimeTrim.Hour(testDay, 14), TimeTrim.Hour(testDay, 15, 30)));
            Console.WriteLine("TimePeriodCollection: " + timePeriods);
            // > TimePeriodCollection: Count = 4; 23.07.2010 08:00:00 - 18:45:00 | 0.10:45
            Console.WriteLine("TimePeriodCollection.Items");
            foreach (ITimePeriod timePeriod in timePeriods)
            {
                Console.WriteLine("Item: " + timePeriod);
            }
            // > Item: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Item: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Item: 23.07.2010 16:15:00 - 18:45:00 | 02:30:00
            // > Item: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00

            // --- intersection by moment ---
            DateTime intersectionMoment = new DateTime(2010, 7, 23, 10, 30, 0);
            ITimePeriodCollection momentIntersections = timePeriods.IntersectionPeriods(intersectionMoment);

            Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionMoment);
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 10:30:00
            foreach (ITimePeriod momentIntersection in momentIntersections)
            {
                Console.WriteLine("Intersection: " + momentIntersection);
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00

            // --- intersection by period ---
            TimeRange             intersectionPeriod  = new TimeRange(TimeTrim.Hour(testDay, 9), TimeTrim.Hour(testDay, 14, 30));
            ITimePeriodCollection periodIntersections = timePeriods.IntersectionPeriods(intersectionPeriod);

            Console.WriteLine("TimePeriodCollection.IntesectionPeriods of " + intersectionPeriod);
            // > TimePeriodCollection.IntesectionPeriods of 23.07.2010 09:00:00 - 14:30:00 | 0.05:30
            foreach (ITimePeriod periodIntersection in periodIntersections)
            {
                Console.WriteLine("Intersection: " + periodIntersection);
            }
            // > Intersection: 23.07.2010 08:00:00 - 11:00:00 | 03:00:00
            // > Intersection: 23.07.2010 10:00:00 - 13:00:00 | 03:00:00
            // > Intersection: 23.07.2010 14:00:00 - 15:30:00 | 01:30:00
        }         // TimePeriodCollectionSample
예제 #10
0
        //Appointment Creation Helper Methods
        //Checking if InsideWorkingHours + Not Weekend
        public static bool IsInWorkingHours(DateTime start, DateTime end)
        {
            DataContext dbApp = new DataContext();

            // check Not Saturday or Sunday
            if (start.DayOfWeek == DayOfWeek.Saturday || start.DayOfWeek == DayOfWeek.Sunday)
            {
                return(false);
            }

            TimeRange workingHours = new TimeRange(TimeTrim.Hour(start, int.Parse(dbApp.Administrations.Find(2).Value)), TimeTrim.Hour(start, int.Parse(dbApp.Administrations.Find(3).Value)));

            return(workingHours.HasInside(new TimeRange(start, end)));
        }
        public static bool IsInWorkingHours(string startHour, string endHour, TimeBlock block, Employee employee)
        {
            var start       = ((int)block.Start.DayOfWeek == 0) ? 7 : (int)block.Start.DayOfWeek;
            var end         = ((int)block.Start.DayOfWeek == 0) ? 7 : (int)block.Start.DayOfWeek;
            var locationEnd = (int)employee.Location.EndDay;

            if (start > locationEnd || end > locationEnd)
            {
                return(false);
            }

            TimeRange workingHours = new TimeRange(TimeTrim.Hour(block.Start.Date, int.Parse(startHour)), TimeTrim.Hour(block.Start.Date, int.Parse(endHour)));

            return(workingHours.HasInside(block));
        }
        // Appointment Creation Helper Methods
        // Checking if InsideWorkingHours + Not Weekend
        public static bool IsInWorkingHours(IStudioDbContext context, Employee employee, DateTime start, DateTime end)
        {
            var startDay       = ((int)start.DayOfWeek == 0) ? 7 : (int)start.DayOfWeek;
            var endDay         = ((int)end.DayOfWeek == 0) ? 7 : (int)end.DayOfWeek;
            var locationEndDay = (int)employee.Location.EndDay;

            if (startDay > locationEndDay || endDay > locationEndDay)
            {
                return(false);
            }

            TimeRange workingHours = new TimeRange(TimeTrim.Hour(start, int.Parse(employee.Location.StartHour)), TimeTrim.Hour(start, int.Parse(employee.Location.EndHour)));

            return(workingHours.HasInside(new TimeRange(start, end)));
        }
예제 #13
0
        }         // GetWorkingPeriods

        // ----------------------------------------------------------------------
        public ITimePeriodCollection GetExcludePeriods(DateTime moment)
        {
            ITimePeriodCollection workingPeriods = GetWorkingPeriods(moment);

            if (workingPeriods.Count == 0)
            {
                return(new TimePeriodCollection());
            }

            DateTime dayStart = TimeTrim.Hour(moment);
            DateTime dayEnd   = dayStart.Add(new TimeSpan(1, 0, 0, 0));
            T        day      = new T();

            day.Setup(dayStart, dayEnd);

            return(new TimeGapCalculator <T>().GetGaps(workingPeriods, day));
        }         // GetExcludePeriods
예제 #14
0
        }         // CalcTimeMoment

        // ----------------------------------------------------------------------
        public static DateTime CalcTimeMoment(DateTime baseMoment, TimeUnit offsetUnit, long offsetCount = 1, ITimeCalendar calendar = null)
        {
            switch (offsetUnit)
            {
            case TimeUnit.Tick:
                return(baseMoment.AddTicks(offsetCount));

            case TimeUnit.Millisecond:
                DateTime offsetMillisecond = baseMoment.AddSeconds(offsetCount);
                return(TimeTrim.Millisecond(offsetMillisecond, offsetMillisecond.Millisecond));

            case TimeUnit.Second:
                DateTime offsetSecond = baseMoment.AddSeconds(offsetCount);
                return(TimeTrim.Second(offsetSecond, offsetSecond.Second));

            case TimeUnit.Minute:
                return(new Minute(baseMoment, calendar).AddMinutes(ToInt(offsetCount)).Start);

            case TimeUnit.Hour:
                return(new Hour(baseMoment, calendar).AddHours(ToInt(offsetCount)).Start);

            case TimeUnit.Day:
                return(new Day(baseMoment, calendar).AddDays(ToInt(offsetCount)).Start);

            case TimeUnit.Week:
                return(new Week(baseMoment, calendar).AddWeeks(ToInt(offsetCount)).Start);

            case TimeUnit.Month:
                return(new Month(baseMoment, calendar).AddMonths(ToInt(offsetCount)).Start);

            case TimeUnit.Quarter:
                return(new Quarter(baseMoment, calendar).AddQuarters(ToInt(offsetCount)).Start);

            case TimeUnit.Halfyear:
                return(new Halfyear(baseMoment, calendar).AddHalfyears(ToInt(offsetCount)).Start);

            case TimeUnit.Year:
                return(new Year(baseMoment, calendar).AddYears(ToInt(offsetCount)).Start);

            default:
                throw new InvalidOperationException();
            }
        }         // CalcTimeMoment
예제 #15
0
 public void MillisecondTest()
 {
     Assert.Equal(TimeTrim.Millisecond(testDate), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, testDate.Second));
     Assert.Equal(TimeTrim.Millisecond(testDate, 128), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, testDate.Second, 128));
 }         // MillisecondTest
예제 #16
0
 public void SecondTest()
 {
     Assert.Equal(TimeTrim.Second(testDate), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 0));
     Assert.Equal(TimeTrim.Second(testDate, 55), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 55));
     Assert.Equal(TimeTrim.Second(testDate, 55, 128), new DateTime(testDate.Year, testDate.Month, testDate.Day, testDate.Hour, testDate.Minute, 55, 128));
 }         // SecondTest