示例#1
0
        /// <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));
        }
示例#2
0
 /// <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));
     }
 }
示例#3
0
        /// <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));
        }
示例#4
0
        /// <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(string id, IList <ZoneLine> zoneList)
        {
            var ruleSets = zoneList.Select(zone => zone.ResolveRules(Rules)).ToList();

            return(DateTimeZoneBuilder.Build(id, ruleSets));
        }