Пример #1
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)
         });
Пример #2
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);
                }
            }
        }