Пример #1
0
        /// <summary>
        /// Checks if dow is open on given date.
        /// If open it returns the date that was input.
        /// If closed it finds most recent day that was open.
        /// e.g. closed on weekends and public holidays so return friday
        /// This Method is not 30w aware and doesn't need to be
        /// </summary>
        /// <param name="date"></param>
        /// <returns>Return the date that should be used for the most recent DJ opening for a given date </returns>
        public static DateTime GetApplicableDJDate(DateTime date)
        {
            //Dow is closed on weekend
            if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
            {
                //Check yesterday
                return(GetApplicableDJDate(date.AddDays(-1)));//WARNING RECURSION
            }

            //Dow is closed on some public holidays
            if (Holidays.Contains(date))
            {
                return(GetApplicableDJDate(date.AddDays(-1)));//WARNING RECURSION
            }

            return(date);
        }
Пример #2
0
        /// <summary>
        /// Returns date n working days backwards from the given one
        /// </summary>
        /// <param name="date">Date to count from</param>
        /// <param name="n">Working days to count backwards</param>
        /// <param name="dayHospital">True if this is day hospital</param>
        public static DateTime WorkingDaysBefore(this DateTime date, int n, bool dayHospital)
        {
            date = date.Date;

            // Day hospital by polyclinic bed days counting differs: in and out days are both to count
            if (dayHospital)
            {
                --n;
            }

            if (dayHospital && DayHospitalSixDaysWeek)
            {
                while (n > 0)
                {
                    date = date.AddDays(-1);
                    DayOfWeek dw = date.DayOfWeek;
                    if ((dw != DayOfWeek.Sunday || Workdays.Contains(date)) && !Holidays.Contains(date))
                    {
                        --n;
                    }
                }
            }
            else
            {
                while (n > 0)
                {
                    date = date.AddDays(-1);
                    DayOfWeek dw = date.DayOfWeek;
                    if (((dw != DayOfWeek.Saturday && dw != DayOfWeek.Sunday) ||
                         Workdays.Contains(date)) && !Holidays.Contains(date))
                    {
                        --n;
                    }
                }
            }
            return(date);
        }
Пример #3
0
        public static bool IsWorkDay(this DateTime date)
        {
            DayOfWeek dw = date.DayOfWeek;

            return(((dw != DayOfWeek.Saturday && dw != DayOfWeek.Sunday) || Workdays.Contains(date)) && !Holidays.Contains(date));
        }