/// <summary>
        /// The witching hour prep is every Saturday night at midnight in October 
        /// except on Halloween when the main event occurs (separate event).
        /// </summary>
        /// <returns></returns>
        private static TemporalExpression BuildWitchingHourPrepTemporalExpression()
        {
            var halloween = new FixedHolidayTE(10, 31);
            var holidays = new UnionTE();
            holidays.Add(halloween);

            var everySaturdayNight = new DayOfMonthTE(6);
            var october = new RangeEachYearTE(10);

            var saturdays = new UnionTE();
            saturdays.Add(everySaturdayNight);

            var intersection = new IntersectionTE();
            intersection.Add(october);
            intersection.Add(saturdays);

            var diff = new DifferenceTE(intersection, holidays);
            return diff;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create and return a base schedule including exclusions if applicable.
        /// </summary>
        /// <param name="excludedDates">Holidays or any excluded dates</param>
        /// <returns>Complete schedule as an expression</returns>
        private TemporalExpression Create(TemporalExpression excludedDates)
        {
            var intersectionTE = new IntersectionTE();

            // get a builder that knows how to create a UnionTE for the event frequency
            var builder = EventFrequencyBuilder.Create(_event);
            var union = builder.Create();
            intersectionTE.Add(union);

            if (_event.RangeInYear != null)
            {
                var rangeEachYear = GetRangeForYear(_event);
                intersectionTE.Add(rangeEachYear);
            }

            return new DifferenceTE(intersectionTE, excludedDates);
        }
        /// <summary>
        /// Street cleaning occurs from April to October on the first and third Monday of the
        /// month, excluding holidays. In this test there are two holidays: July 4 and Labor
        /// Day (first Monday in Sep). The street cleaning example is taken directly from 
        /// Martin Fowler's white paper "Recurring Events for Calendars".
        /// </summary>
        private static TemporalExpression BuildStreetCleaningTemporalExpression()
        {
            var maHolidays = new UnionTE();
            var independenceDay = new FixedHolidayTE(7, 4);
            var laborDay = new FloatingHolidayTE(9, 1, 1);

            maHolidays.Add(independenceDay);
            maHolidays.Add(laborDay);

            var firstMondayFirstWeek = new DayInMonthTE(1, 1);
            var firstMondayThirdWeek = new DayInMonthTE(1, 3);

            var firstAndThirdMonday = new UnionTE();
            firstAndThirdMonday.Add(firstMondayThirdWeek);
            firstAndThirdMonday.Add(firstMondayFirstWeek);

            var streetCleaningMonths = new IntersectionTE();
            streetCleaningMonths.Add(firstAndThirdMonday);
            streetCleaningMonths.Add(new RangeEachYearTE(3, 9));
            var diff = new DifferenceTE(streetCleaningMonths, maHolidays);
            return diff;
        }