public static bool IsWorkingDay(this DateTime day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     if (!workingDayCultureInfo.IsWorkingDay(day.DayOfWeek)) {
         return false;
     }
     return workingDayCultureInfo.IsWorkingDay(day);
 }
Esempio n. 2
0
 /// <summary>
 /// Checks if a specific day is a working day.
 /// </summary>
 /// <param name="day">The day from calendar to check</param>
 /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the check if the day is a working day</param>
 /// <returns></returns>
 public static bool IsWorkingDay(this DateTime day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     if (!workingDayCultureInfo.IsWorkingDay(day.DayOfWeek))
     {
         return(false);
     }
     return(workingDayCultureInfo.IsWorkingDay(day));
 }
 public static IDictionary<DateTime, Holiday> AllYearHolidays(this DateTime day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     var holidays = new SortedDictionary<DateTime, Holiday>();
     foreach (Holiday holiday in workingDayCultureInfo.Holidays) {
         var date = holiday.GetInstance(day.Year);
         holidays.Add(date, holiday);
     }
     return holidays;
 }
Esempio n. 4
0
        /// <summary>
        /// Retrieves the holidays that have and are still ocouring on the <paramref name="day" /> year.
        /// </summary>
        /// <param name="day">The day used to gat the year from.</param>
        /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the get the holidays.</param>
        /// <returns>Returns a dictionary with the instance of the holiday observed on the year, and the holiday that gave it the observance.</returns>
        public static IDictionary <DateTime, Holiday> AllYearHolidays(this DateTime day,
                                                                      IWorkingDayCultureInfo workingDayCultureInfo)
        {
            var holidays = new SortedDictionary <DateTime, Holiday>();

            foreach (KeyValuePair <DateTime, Holiday> holiday in workingDayCultureInfo.GetObservancesOfYear(day.Year))
            {
                var date = holiday.Key;
                holidays.Add(date, holiday.Value);
            }
            return(holidays);
        }
        /// <summary>
        /// Adds or subctracts the value in <paramref name="workingDays"/> as working days to <paramref name="day"/>. 
        /// </summary>
        /// <remarks>
        /// This algorithm is only efficient for small values of workingDays.
        /// </remarks>
        /// <param name="day">The starting day.</param>
        /// <param name="workingDays">The number of working days to be added or subtracted.</param>
        /// <param name="cultureWorkingDayInfo">The culture of working days to be used in the calculation</param>
        /// <returns>Returns a <typeparamref name="DateTime"/> with the value of the day 
        /// with <paramref name="workingDays"/> added or subctracted to <paramref name="day"/>
        /// </returns>
        public static DateTime AddWorkingDays(this DateTime day, int workingDays, IWorkingDayCultureInfo workingDayCultureInfo)
        {
            DateTime ret;
            int added = 0;

            ret = day.Subtract(day.TimeOfDay);
            while (added < Math.Abs(workingDays)) {
                ret = ret.AddDays((workingDays >= 0)? 1 : -1);
                if (IsWorkingDay(ret, workingDayCultureInfo)) {
                    added++;
                }
            }
            return ret;
        }
        /// <summary>
        /// Retrieves the holidays that have and are still ocouring on the <paramref name="day" /> year.
        /// </summary>
        /// <param name="day">The day used to gat the year from.</param>
        /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the get the holidays.</param>
        /// <returns>Returns a dictionary with the instance of the holiday observed on the year, and the holiday that gave it the observance.</returns>
        public static IDictionary <DateTime, Holiday> AllYearHolidays(this DateTime day,
                                                                      IWorkingDayCultureInfo workingDayCultureInfo)
        {
            var holidays = new SortedDictionary <DateTime, Holiday>();

            foreach (Holiday holiday in workingDayCultureInfo.GetHolidaysOfYear(day.Year))
            {
                var date = holiday.GetInstance(day.Year);
                if (date.HasValue)
                {
                    holidays.Add(date.Value, holiday);
                }
            }
            return(holidays);
        }
        /// <summary>
        /// Adds or subctracts the value in <paramref name="workingDays"/> as working days to <paramref name="day"/>.
        /// </summary>
        /// <remarks>
        /// This algorithm is only efficient for small values of workingDays.
        /// </remarks>
        /// <param name="day">The starting day.</param>
        /// <param name="workingDays">The number of working days to be added or subtracted.</param>
        /// <param name="cultureWorkingDayInfo">The culture of working days to be used in the calculation</param>
        /// <returns>Returns a <typeparamref name="DateTime"/> with the value of the day
        /// with <paramref name="workingDays"/> added or subctracted to <paramref name="day"/>
        /// </returns>
        public static DateTime AddWorkingDays(this DateTime day, int workingDays, IWorkingDayCultureInfo workingDayCultureInfo)
        {
            DateTime ret;
            int      added = 0;

            ret = day.Subtract(day.TimeOfDay);
            while (added < Math.Abs(workingDays))
            {
                ret = ret.AddDays((workingDays >= 0)? 1 : -1);
                if (IsWorkingDay(ret, workingDayCultureInfo))
                {
                    added++;
                }
            }
            return(ret);
        }
Esempio n. 8
0
 /// <summary>
 /// Checks if a specific day is an holiday desregarding the day of the week.
 /// </summary>
 /// <param name="day">The day from calendar to check</param>
 /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the check if the day is a working day</param>
 /// <returns></returns>
 public static bool IsHoliday(this DateTime day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     return(workingDayCultureInfo.IsHoliday(day));
 }
 /// <summary>
 /// Checks if a specific day is an holiday desregarding the day of the week.
 /// </summary>
 /// <param name="day">The day from calendar to check</param>
 /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the check if the day is a working day</param>
 /// <returns></returns>
 public static bool IsHoliday(this DateTime day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     return workingDayCultureInfo.IsHoliday(day);
 }
 private void TestHoliday(IWorkingDayCultureInfo workingDayCultureInfo, DateTime dateOnGregorian)
 {
     var isHoliday = workingDayCultureInfo.IsHoliday(dateOnGregorian);
     Assert.IsTrue(isHoliday);
 }
        private void TestHoliday(IWorkingDayCultureInfo workingDayCultureInfo, DateTime dateOnGregorian)
        {
            var isHoliday = workingDayCultureInfo.IsHoliday(dateOnGregorian);

            Assert.IsTrue(isHoliday);
        }
 /// <summary>
 /// Adds or subctracts the value in <paramref name="workingDays"/> as working days to <paramref name="day"/>.
 /// </summary>
 /// <remarks>
 /// This algorithm is only efficient for small values of workingDays.
 /// </remarks>
 /// <param name="day">The starting day.</param>
 /// <param name="workingDays">The number of working days to be added or subtracted.</param>
 /// <param name="workingDayCultureInfo">The culture of working days to be used in the calculation. See <seealso cref="WorkingDayCultureInfo"/> for more information.</param>
 /// <returns>Returns a DateTimeOffset representing a date
 /// with <paramref name="workingDays"/> added or subctracted to <paramref name="day"/>
 /// </returns>
 public static DateTimeOffset AddWorkingDays(this DateTimeOffset day, int workingDays,
                                             IWorkingDayCultureInfo workingDayCultureInfo)
 {
     return(day.Date.AddWorkingDays(workingDays, workingDayCultureInfo));
 }
 /// <summary>
 /// Retrieves the holidays that have and are still ocouring on the <paramref name="day" /> year.
 /// </summary>
 /// <param name="day">The day used to gat the year from.</param>
 /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the get the holidays.</param>
 /// <returns>Returns a dictionary with the instance of the holiday observed on the year, and the holiday that gave it the observance.</returns>
 public static IDictionary <DateTimeOffset, Holiday> AllYearHolidays(this DateTimeOffset day,
                                                                     IWorkingDayCultureInfo workingDayCultureInfo)
 {
     return(day.Date.AllYearHolidays(workingDayCultureInfo).ToDictionary(x => (DateTimeOffset)x.Key, x => x.Value));
 }
 /// <summary>
 /// Checks if a specific day is a working day.
 /// </summary>
 /// <param name="day">The day from calendar to check</param>
 /// <param name="workingDayCultureInfo">The <seealso cref="IWorkingDayCultureInfo"/> used the check if the day is a working day</param>
 /// <returns></returns>
 public static bool IsWorkingDay(this DateTimeOffset day, IWorkingDayCultureInfo workingDayCultureInfo)
 {
     return(day.Date.IsWorkingDay(workingDayCultureInfo));
 }
Esempio n. 15
0
        private void AssertIsNotHoliday(IWorkingDayCultureInfo workingDayCultureInfo, DateTime dateOnGregorian)
        {
            var isHoliday = workingDayCultureInfo.IsHoliday(dateOnGregorian);

            Assert.IsFalse(isHoliday);
        }