Пример #1
0
        /// <summary>
        ///     Parse a day rule expression
        ///     A Day Rule Expression is:
        ///     * * * * [[{description}]] {working periods}  #{comments}
        ///     ^ ^ ^ ^ ^                     ^              ^
        ///     | | | | |                     |              +- (Optional) EoL comment
        ///     | | | | |                     |
        ///     | | | | |                     +---------------- (Optional) Comma separated list of working periods
        ///     | | | | |
        ///     | | | | +-------------------------------------- (Optional) Description of the day
        ///     | | | |
        ///     | | | +---------------------------------------- Day of Week rule
        ///     | | |
        ///     | | +------------------------------------------ Day of Month rule
        ///     | |
        ///     | +-------------------------------------------- Month rule
        ///     |
        ///     +---------------------------------------------- Year rule
        ///     <example>
        ///         Every day non working day: * * * * [[]]
        ///         Every day working day: * * * * [[]] 08:30-17:30
        ///         Vacancy on 29th of february: * * 29 * * [[vacancy on the extra day]]
        ///         Vacancy on 1st of march of leap years: */Leap 3 1 * [[Vacancy on the extra day]]
        ///         Ordinary working days: * * * 1..5 [[]] 08:30-13:30,14:30-17:30
        ///     </example>
        /// </summary>
        public static bool TryParse(string value, out DayRule dayRule)
        {
            dayRule = default;
            if (string.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            if (!TryParseInternal(value, out var description, out var yearMatchers, out var monthMatchers, out var dayOfMonthMatchers, out var dayOfWeekMatchers, out var timePeriods))
            {
                return(false);
            }

            dayRule = new DayRule(description, yearMatchers, monthMatchers, dayOfMonthMatchers, dayOfWeekMatchers,
                                  timePeriods);

            return(true);
        }
 public void Add(DayRulePolicy policy, DayRule rule) => Add(new CalendarRule(policy, rule));
 public CalendarRule(DayRulePolicy policy, DayRule rule)
 {
     Policy = policy;
     Rule   = rule ?? throw new ArgumentNullException(nameof(rule));
 }