Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TzdbDatabase" /> class.
 /// </summary>
 internal TzdbDatabase(string version)
 {
     zoneLists       = new SortedList <string, ZoneList>();
     Rules           = new Dictionary <string, IList <ZoneRule> >();
     Aliases         = new Dictionary <string, string>();
     currentZoneList = null;
     this.Version    = version;
 }
Beispiel #2
0
        /// <summary>
        /// Adds the given zone to the current zone list. If there is no zone list or the
        /// zone is for a different named zone a new zone list is created.
        /// </summary>
        /// <param name="zone">The zone to add.</param>
        internal void AddZone(Zone zone)
        {
            var name = zone.Name;

            if (String.IsNullOrEmpty(name))
            {
                if (currentZoneList == null)
                {
                    throw new InvalidOperationException("A continuation zone must be preceeded by an initially named zone");
                }
                name = currentZoneList.Name;
            }
            if (currentZoneList == null || currentZoneList.Name != name)
            {
                currentZoneList = new ZoneList();
                zoneLists.Add(name, currentZoneList);
            }
            currentZoneList.Add(zone);
        }
Beispiel #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));
        }