/// <summary> /// Initialise une nouvelle instance de <see cref="DayOfRule"/> /// </summary> /// <param name="dayWork">Type de positionnement</param> /// <param name="dayWeek">Jour de la semaine à respecter</param> /// <param name="dayMonth">Jour du mois à respecter</param> public DayOfRule(DayWorkKind dayWork, DayOfWeek dayWeek, int dayMonth) { _dwork = dayWork; _dweek = dayWeek; _dmonth = dayMonth; }
/// <summary> /// Remplit une règle avec les paramètres spécifiés /// </summary> /// <param name="rp">Règle à complèter</param> /// <param name="monthp">IN / UNTILMONTH</param> /// <param name="dayp">ON / UNTILDAY</param> /// <param name="timep">AT / UNTILTIME</param> private static void SetRuleSub(RuleDate rp, string monthp, string dayp, string timep) { // Month (IN) rp.Month = TzUtilities.GetMonth(monthp); // (AT) rp.AtKind = TimeKind.LocalWallTime; if (timep.EndsWith("s", StringComparison.InvariantCulture)) { rp.AtKind = TimeKind.LocalStandardTime; rp.At = TzUtilities.GetHMS(timep.Substring(0, timep.Length - 1)); } else if (timep.EndsWith("w", StringComparison.InvariantCulture)) { rp.AtKind = TimeKind.LocalWallTime; rp.At = TzUtilities.GetHMS(timep.Substring(0, timep.Length - 1)); } else if (timep.EndsWith("g", StringComparison.InvariantCulture) || timep.EndsWith("u", StringComparison.InvariantCulture) || timep.EndsWith("z", StringComparison.InvariantCulture)) { rp.AtKind = TimeKind.UniversalTime; rp.At = TzUtilities.GetHMS(timep.Substring(0, timep.Length - 1)); } else { rp.At = TzUtilities.GetHMS(timep); } // Day work (ON) // Accept thing such as // 1 // last-Sunday // Sun<=20 // Sun>=7 var lday = LastDays.Select((e, i) => new { Name = e, Day = DayWeek[i] }).Where(e => itsabbr(dayp, e.Name)); if (lday.Count() == 1) { rp.Day = new DayOfRule(DayWorkKind.DowLeq, lday.ElementAt(0).Day, -1); } else { int index = 0; DayWorkKind dw = DayWorkKind.Dom; if ((index = dayp.IndexOf("<", StringComparison.InvariantCulture)) != -1) { dw = DayWorkKind.DowLeq; } else if ((index = dayp.IndexOf(">", StringComparison.InvariantCulture)) != -1) { dw = DayWorkKind.DowGeq; } else { index = 0; dw = DayWorkKind.Dom; } DayOfWeek dweek = DayOfWeek.Sunday; if (dw != DayWorkKind.Dom) { index++; if (dayp[index++] != '=') { throw new ArgumentException("Invalid day of month", dayp); } var lp = DayNames.Select((e, i) => new { Name = e, Day = DayWeek[i] }).Where(e => itsabbr(dayp.Substring(0, index - 2), e.Name)); if (lp.Count() != 1) { throw new ArgumentException("Invalid weekday name", dayp); } dweek = lp.ElementAt(0).Day; } rp.Day = new DayOfRule(dw, dweek, Convert.ToInt32(dayp.Substring(index), CultureInfo.InvariantCulture)); if (rp.Day.DayOfMonth <= 0 || rp.Day.DayOfMonth > LenOfMonths[rp.Month - 1]) { throw new ArgumentException("Invalid day of month", dayp); } } }