Beispiel #1
0
 /// <summary>
 /// Returns the input date, adjusted by rolling backwards if the input date falls on a holiday according to the specified calendar
 /// </summary>
 /// <param name="input">Input date</param>
 /// <param name="calendar">Calendar</param>
 /// <returns></returns>
 public static DateTime IfHolidayRollBack(this DateTime input, Calendar calendar)
 {
     while (calendar.IsHoliday(input))
     {
         input = input.AddDays(-1);
     }
     return(input);
 }
Beispiel #2
0
 /// <summary>
 /// Returns the input date, adjusted by rolling forward if the input date falls on a holiday according to the specified calendar
 /// </summary>
 /// <param name="input">Input date</param>
 /// <param name="calendar">Calendar</param>
 /// <returns></returns>
 public static DateTime IfHolidayRollForward(this DateTime input, Calendar calendar)
 {
     input = input.Date;
     while (calendar.IsHoliday(input))
     {
         input = input.AddDays(1);
     }
     return(input);
 }
Beispiel #3
0
        public static DateTime[] HolidaysForRange(this Calendar calendar, DateTime start, DateTime end)
        {
            var o = new List <DateTime>();
            var d = start;

            while (d <= end)
            {
                if (calendar.IsHoliday(d))
                {
                    o.Add(d);
                }
                if (d.DayOfWeek == DayOfWeek.Friday)
                {
                    d = d.AddDays(3);
                }
                else
                {
                    d = d.AddDays(1);
                }
            }
            return(o.ToArray());
        }