public bool IsHoliday(DateTime date) { if (CalendarType != CalendarType.Regular) { return(IsHolidayFromRules(date)); } if (MonthsToExclude.Contains((MonthEnum)date.Month)) { return(true); } if (DaysToAlwaysExclude.Contains(date.DayOfWeek)) { return(true); } else if (DaysToExclude.Contains(date.Date)) { return(true); } foreach (var ic in InheritedCalendarObjects) { if (ic.IsHoliday(date)) { return(true); } } return(false); }
public Calendar Clone() { var newCalender = new Calendar() { DaysToAlwaysExclude = DaysToAlwaysExclude.ToList(), InheritedCalendar = InheritedCalendar.ToList(), DaysToExclude = new HashSet <DateTime>(DaysToExclude), MonthsToExclude = MonthsToExclude.ToList(), Name = Name }; return(newCalender); }
public Calendar Merge(Calendar otherCalendar) { if (otherCalendar.CalendarType != CalendarType) { throw new Exception("Cannot merge calendars of differing types"); } var newCalender = new Calendar() { DaysToAlwaysExclude = DaysToAlwaysExclude.Concat(otherCalendar.DaysToAlwaysExclude).Distinct().ToList(), InheritedCalendar = InheritedCalendar.Concat(otherCalendar.InheritedCalendar).Distinct().ToList(), DaysToExclude = new HashSet <DateTime>(DaysToExclude.Concat(otherCalendar.DaysToExclude).Distinct()), MonthsToExclude = MonthsToExclude.Concat(otherCalendar.MonthsToExclude).Distinct().ToList(), Name = Name }; return(newCalender); }