Ejemplo n.º 1
0
            internal Calendar GetCalendar()
            {
                var rules = new CalendarRules();

                foreach (var r in Rules)
                {
                    if (!DayRuleParser.TryParseInternal(r.Pattern,
                                                        out var description,
                                                        out var yearMatchers,
                                                        out var monthMatchers,
                                                        out var dayOfMonthMatchers,
                                                        out var dayOfWeekMatchers,
                                                        out var workingPeriods))
                    {
                        throw new SerializationException($"Day pattern '{r.Pattern}' is invalid");
                    }
                    if (!string.IsNullOrEmpty(description))
                    {
                        throw new SerializationException(
                                  $"Day pattern '{r.Pattern}' is invalid in this context: you cannot provide a day description");
                    }
                    if (workingPeriods is not null)
                    {
                        throw new SerializationException(
                                  $"Day pattern '{r.Pattern}' is invalid in this context: you cannot provide a working period list");
                    }
                    rules.Add(Enum.Parse <DayRulePolicy>(r.Policy), r.Description, yearMatchers, monthMatchers,
                              dayOfMonthMatchers, dayOfWeekMatchers,
                              r.WorkingPeriods?.Select(_ => new TimePeriod(Time.Parse(_.Begin), Time.Parse(_.End))));
                }

                return(new Calendar(Name, rules, Description, LongDescription));
            }
Ejemplo n.º 2
0
 public string ToDayPatternString() => DayRuleParser.ToDayPatternString(YearMatchers, MonthMatchers, DayOfMonthMatchers, DayOfWeekMatchers);