Beispiel #1
0
        private static DateTime GetNewWorkDay(DateTime date, HolidayProvider holidays)
        {
            var newDate = GetNewDate(date.AddDays(1), new TimeSpan(8, 0, 0));

            newDate = WorkDayProvider.Validate(newDate, holidays);
            newDate = WorkHourProvider.Validate(newDate, holidays);
            return(holidays.Validate(newDate));
        }
Beispiel #2
0
        public DateTime GetEndDate(DateTime start, int minutes)
        {
            var      holidays     = new HolidayProvider(start.Year);
            DateTime newStartDate = CheckStartDate(start, holidays);

            Console.WriteLine($"  Validated start date: {newStartDate.GetDateString()}");
            return(CheckEndDate(newStartDate, minutes, holidays));
        }
 public static DateTime Validate(DateTime date, HolidayProvider holidays)
 {
     while (IsNotWorkDay(date))
     {
         date = date.AddDays(1);
         date = holidays.Validate(date);
     }
     return(date);
 }
Beispiel #4
0
        private DateTime CheckEndDate(DateTime newStartDate, int minutes, HolidayProvider holidays)
        {
            var endDate = TimeTools.AddMinutes(newStartDate, minutes, holidays);

            endDate = holidays.Validate(endDate);
            endDate = WorkDayProvider.Validate(endDate, holidays);
            endDate = WorkHourProvider.Validate(endDate, holidays);
            return(endDate);
        }
Beispiel #5
0
 private DateTime CheckStartDate(DateTime start, HolidayProvider holidays)
 {
     //Check the start date
     start = holidays.Validate(start);
     //Compensate for Saturday and Sunday
     start = WorkDayProvider.Validate(start, holidays);
     //Ensure only work hours are used
     start = WorkHourProvider.Validate(start, holidays);
     return(start);
 }
Beispiel #6
0
        public static DateTime Validate(DateTime date, HolidayProvider holidays)
        {
            var time = date.TimeOfDay;

            //time is at or before 8AM
            if (time < clockIn)
            {
                return(GetNewDate(date, time, clockIn));
            }
            //time is between 8AM and 12noon
            if (time >= clockIn && time <= clockOut)
            {
                return(date);
            }
            //time is between 12noon and 1pm
            if (time >= clockOut && time <= clockInAfter)
            {
                return(GetNewDate(date, time, clockInAfter));
            }
            //time is between 1pm and 5pm
            if (time >= clockInAfter && time < clockOutAfter)
            {
                return(date);
            }
            //time is 5pm
            if (time == clockOutAfter)
            {
                return(date);
            }
            //time is after 5pm
            if (time >= clockOutAfter)
            {
                date = TimeTools.GetNewDate(date.AddDays(1), clockIn);
                date = WorkDayProvider.Validate(date, holidays);
                date = holidays.Validate(date);
            }
            return(date);
        }
Beispiel #7
0
        public static DateTime AddMinutes(DateTime date, int minutes, HolidayProvider holidays)
        {
            //NOTE: split this into testable fragments
            int workDayMinutes          = 480;
            int halfDayMinutes          = 240;
            int lunchMinutes            = 60;
            int workDayMinutesWithLunch = workDayMinutes + lunchMinutes;
            int workDays = Math.Abs(minutes / workDayMinutes);

            if (workDays < 1)
            {
                return(date.AddMinutes(minutes));;
            }
            int minLeft = minutes;

            //Console.WriteLine($"  work days: {workDays}");

            for (int i = 0; i <= workDays - 1; i++)
            {
                if (minLeft > 0 && minLeft < workDayMinutes)
                {
                    if (minLeft > halfDayMinutes)
                    {
                        minLeft += lunchMinutes;                                              //add the lunch hour for accurate time
                    }
                    return(date.AddMinutes(minLeft));
                }
                date     = date.AddMinutes(workDayMinutesWithLunch);
                minLeft -= workDayMinutes;
                if (minLeft >= workDayMinutes)
                {
                    date = GetNewWorkDay(date, holidays);
                }
            }
            return(date);
        }