示例#1
0
 internal void HandleStringPoolField(TzdbStreamField field)
 {
     CheckSingleField(field, stringPool);
     using (var stream = field.CreateStream())
     {
         var reader = new DateTimeZoneReader(stream, null);
         int count  = reader.ReadCount();
         stringPool = new string[count];
         for (int i = 0; i < count; i++)
         {
             stringPool[i] = reader.ReadString();
         }
     }
 }
示例#2
0
 internal void HandleZoneField(TzdbStreamField field)
 {
     CheckStringPoolPresence(field);
     // Just read the ID from the zone - we don't parse the data yet.
     // (We could, but we might as well be lazy.)
     using (var stream = field.CreateStream())
     {
         var    reader = new DateTimeZoneReader(stream, stringPool);
         string id     = reader.ReadString();
         if (zoneFields.ContainsKey(id))
         {
             throw new InvalidNodaDataException("Multiple definitions for zone " + id);
         }
         zoneFields[id] = field;
     }
 }
示例#3
0
 /// <summary>
 /// Creates the <see cref="DateTimeZone"/> for the given canonical ID, which will definitely
 /// be one of the values of the TzdbAliases dictionary.
 /// </summary>
 /// <param name="id">ID for the returned zone, which may be an alias.</param>
 /// <param name="canonicalId">Canonical ID for zone data</param>
 public DateTimeZone CreateZone(string id, string canonicalId)
 {
     Preconditions.CheckNotNull(id, nameof(id));
     Preconditions.CheckNotNull(canonicalId, nameof(canonicalId));
     using (var stream = zoneFields[canonicalId].CreateStream())
     {
         var reader = new DateTimeZoneReader(stream, stringPool);
         // Skip over the ID before the zone data itself
         reader.ReadString();
         var type = (DateTimeZoneWriter.DateTimeZoneType)reader.ReadByte();
         return(type switch
         {
             DateTimeZoneWriter.DateTimeZoneType.Fixed => FixedDateTimeZone.Read(reader, id),
             DateTimeZoneWriter.DateTimeZoneType.Precalculated =>
             CachedDateTimeZone.ForZone(PrecalculatedDateTimeZone.Read(reader, id)),
             _ => throw new InvalidNodaDataException("Unknown time zone type " + type)
         });
示例#4
0
        /// <inheritdoc />
        public DateTimeZone CreateZone(string id, string canonicalId)
        {
            using (var stream = zoneFields[canonicalId].CreateStream())
            {
                var reader = new DateTimeZoneReader(stream, stringPool);
                // Skip over the ID before the zone data itself
                reader.ReadString();
                var type = (DateTimeZoneWriter.DateTimeZoneType)reader.ReadByte();
                switch (type)
                {
                case DateTimeZoneWriter.DateTimeZoneType.Fixed:
                    return(FixedDateTimeZone.Read(reader, id));

                case DateTimeZoneWriter.DateTimeZoneType.Precalculated:
                    return(CachedDateTimeZone.ForZone(PrecalculatedDateTimeZone.Read(reader, id)));

                default:
                    throw new InvalidNodaDataException("Unknown time zone type " + type);
                }
            }
        }