/// <summary> /// Retrieves the recurrence, after applying the specified name format. /// </summary> /// <remarks> /// Multiple zones may apply the same set of rules as to when they change into/out of /// daylight saving time, but with different names. /// </remarks> /// <param name="zone">The zone for which this rule is being considered.</param> public IEnumerable <ZoneRecurrence> GetRecurrences(ZoneLine zone) { string name = zone.FormatName(recurrence.Savings, daylightSavingsIndicator); if (Type == null) { yield return(recurrence.WithName(name)); } else { Predicate <int> yearPredicate = GetYearPredicate(); // Apply a little sanity... if (recurrence.IsInfinite || recurrence.ToYear - recurrence.FromYear > 1000) { throw new NotSupportedException("Noda Time does not support 'typed' rules over large periods"); } for (int year = recurrence.FromYear; year <= recurrence.ToYear; year++) { if (yearPredicate(year)) { yield return(recurrence.ForSingleYear(year).WithName(name)); } } } }
public void WithName() { var yearOffset = new ZoneYearOffset(TransitionMode.Utc, 10, 31, (int)IsoDayOfWeek.Wednesday, true, LocalTime.Midnight); var original = new ZoneRecurrence("original", Offset.FromHours(1), yearOffset, 1900, 2000); var renamed = original.WithName("renamed"); Assert.AreEqual("renamed", renamed.Name); Assert.AreEqual(original.Savings, renamed.Savings); Assert.AreEqual(original.YearOffset, renamed.YearOffset); Assert.AreEqual(original.FromYear, renamed.FromYear); Assert.AreEqual(original.ToYear, renamed.ToYear); }