public void FixedZone_Eastern() { var offset = Offset.FromHours(5); var builder = new DateTimeZoneBuilder(); builder.SetStandardOffset(offset); builder.SetFixedSavings("GMT-5", Offset.Zero); var zone = builder.ToDateTimeZone("GMT-5"); FixedDateTimeZone fixedZone = (FixedDateTimeZone)zone; Assert.AreEqual(offset, fixedZone.Offset); }
public void FixedZone_Eastern() { var offset = Offset.FromHours(5); var rules = new List <ZoneRuleSet> { new ZoneRuleSet("GMT-5", offset, Offset.Zero, int.MaxValue, null) }; var zone = DateTimeZoneBuilder.Build("GMT-5", rules); FixedDateTimeZone fixedZone = (FixedDateTimeZone)zone; Assert.AreEqual(offset, fixedZone.Offset); }
public void FixedZone_Eastern() { var offset = Offset.FromHours(5); var builder = new DateTimeZoneBuilder(); builder.SetStandardOffset(offset); builder.SetFixedSavings("GMT-5", Offset.Zero); var zone = builder.ToDateTimeZone("GMT-5"); FixedDateTimeZone fixedZone = (FixedDateTimeZone)zone; Assert.AreEqual(offset, fixedZone.Offset); }
/// <summary> /// Builds a time zone with the given ID from a sequence of rule sets. /// </summary> internal static DateTimeZone Build(string id, IList<ZoneRuleSet> ruleSets) { Preconditions.CheckArgument(ruleSets.Count > 0, nameof(ruleSets), "Cannot create a time zone without any Zone entries"); var builder = new DateTimeZoneBuilder(); return builder.BuildZone(id, ruleSets); }
/// <summary> /// Adds a recurring savings rule to the time zone builder. /// </summary> /// <param name="builder">The <see cref="DateTimeZoneBuilder" /> to add to.</param> /// <param name="nameFormat">The name format pattern.</param> /// <param name="ruleSet">The <see cref="ZoneRecurrenceCollection" /> describing the recurring savings.</param> private static void AddRecurring(DateTimeZoneBuilder builder, String nameFormat, IEnumerable<ZoneRule> ruleSet) { foreach (var rule in ruleSet) { string name = rule.FormatName(nameFormat); builder.AddRecurringSavings(rule.Recurrence.WithName(name)); } }
/// <summary> /// Returns a newly created <see cref="DateTimeZone" /> built from the given time zone data. /// </summary> /// <param name="zoneList">The time zone definition parts to add.</param> private DateTimeZone CreateTimeZone(ZoneList zoneList) { var builder = new DateTimeZoneBuilder(); foreach (Zone zone in zoneList) { builder.SetStandardOffset(zone.Offset); if (zone.Rules == null) { builder.SetFixedSavings(zone.Format, Offset.Zero); } else { IList<ZoneRule> ruleSet; if (Rules.TryGetValue(zone.Rules, out ruleSet)) { AddRecurring(builder, zone.Format, ruleSet); } else { try { // Check if Rules actually just refers to a savings. var savings = ParserHelper.ParseOffset(zone.Rules); builder.SetFixedSavings(zone.Format, savings); } catch (FormatException) { throw new ArgumentException( String.Format("Daylight savings rule name '{0}' for zone {1} is neither a known ruleset nor a fixed offset", zone.Rules, zone.Name)); } } } if (zone.UntilYear == Int32.MaxValue) { break; } builder.AddCutover(zone.UntilYear, zone.UntilYearOffset); } return builder.ToDateTimeZone(zoneList.Name); }