protected override string GetText(DailyRecurrenceRule rrule, CultureInfo cultureInfo) { if (rrule == null) { throw new ArgumentNullException(nameof(rrule)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } var sb = new StringBuilder(); sb.Append("every"); if (rrule.Interval == 1) { sb.Append(" day"); } else if (rrule.Interval == 2) { sb.Append(" other day"); } else if (rrule.Interval > 2) { sb.Append(" "); sb.Append(rrule.Interval); sb.Append(" days"); } GetEndHumanText(rrule, sb); return(sb.ToString()); }
protected override string GetText(DailyRecurrenceRule rrule, CultureInfo cultureInfo) { if (rrule == null) { throw new ArgumentNullException(nameof(rrule)); } if (cultureInfo == null) { throw new ArgumentNullException(nameof(cultureInfo)); } var sb = new StringBuilder(); sb.Append("tous les"); if (rrule.Interval == 1) { sb.Append(" jours"); } else { sb.Append(' '); sb.Append(rrule.Interval); sb.Append(" jours"); } GetHumanEnd(rrule, sb); return(sb.ToString()); }
public static bool TryParse(string rrule, out RecurrenceRule recurrenceRule, out string error) { if (rrule == null) { throw new ArgumentNullException(nameof(rrule)); } recurrenceRule = null; error = null; try { // Extract parts IDictionary <string, string> values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var parts = rrule.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var part in parts) { var split = SplitPart(part); if (values.ContainsKey(split.Item1)) { error = $"Duplicate name: '{split.Item1}'."; return(false); } if (string.Equals("UNTIL", split.Item1, StringComparison.OrdinalIgnoreCase) && values.ContainsKey("COUNT")) { error = "Cannot set UNTIL and COUNT in the same recurrence rule."; return(false); } if (string.Equals("COUNT", split.Item1, StringComparison.OrdinalIgnoreCase) && values.ContainsKey("UNTIL")) { error = "Cannot set UNTIL and COUNT in the same recurrence rule."; return(false); } values.Add(split.Item1, split.Item2); } // Set specific properties var frequency = values.GetValue("FREQ", Frequency.None); switch (frequency) { case Frequency.Daily: var dailyRecurrenceRule = new DailyRecurrenceRule { ByMonthDays = ParseByMonthDays(values), ByMonths = ParseByMonth(values), ByWeekDays = ParseByDay(values) }; recurrenceRule = dailyRecurrenceRule; break; case Frequency.Weekly: var weeklyRecurrence = new WeeklyRecurrenceRule { ByMonths = ParseByMonth(values), ByWeekDays = ParseByDay(values) }; recurrenceRule = weeklyRecurrence; break; case Frequency.Monthly: var monthlyRecurrence = new MonthlyRecurrenceRule { ByWeekDays = ParseByDayWithOffset(values), ByMonthDays = ParseByMonthDays(values), ByMonths = ParseByMonth(values) }; recurrenceRule = monthlyRecurrence; break; case Frequency.Yearly: var yearlyRecurrence = new YearlyRecurrenceRule { ByWeekDays = ParseByDayWithOffset(values), ByMonthDays = ParseByMonthDays(values), BySetPositions = ParseBySetPos(values), ByMonths = ParseByMonth(values), ByYearDays = ParseByYearDay(values) }; //yearlyRecurrence.ByWeekNo = ParseByWeekNo(values); recurrenceRule = yearlyRecurrence; break; default: error = "Unknown Frequency (FREQ)."; return(false); } // Set general properties // Set Interval recurrenceRule.Interval = values.GetValue("INTERVAL", 1); recurrenceRule.Occurrences = values.GetValue("COUNT", (int?)null); var until = values.GetValue("UNTIL", (string)null); if (until != null) { recurrenceRule.EndDate = Utilities.ParseDateTime(until); } recurrenceRule.BySetPositions = ParseBySetPos(values); recurrenceRule.WeekStart = ParseWeekStart(values); return(true); } catch (FormatException e) { error = e.Message; return(false); } }
protected abstract string GetText(DailyRecurrenceRule rrule, CultureInfo cultureInfo);