public static ZoneYearOffset Read([NotNull] IDateTimeZoneReader reader)
        {
            Preconditions.CheckNotNull(reader, nameof(reader));
            int flags       = reader.ReadByte();
            var mode        = (TransitionMode)(flags >> 5);
            var dayOfWeek   = (flags >> 2) & 7;
            var advance     = (flags & 2) != 0;
            var addDay      = (flags & 1) != 0;
            int monthOfYear = reader.ReadCount();
            int dayOfMonth  = reader.ReadSignedCount();
            // The time of day is written as a number of milliseconds for historical reasons.
            var timeOfDay = LocalTime.FromMillisecondsSinceMidnight(reader.ReadMilliseconds());

            return(new ZoneYearOffset(mode, monthOfYear, dayOfMonth, dayOfWeek, advance, timeOfDay, addDay));
        }
Exemple #2
0
        public static ZoneYearOffset Read(IDateTimeZoneReader reader)
        {
            Preconditions.CheckNotNull(reader, "reader");
            int flags       = reader.ReadByte();
            var mode        = (TransitionMode)(flags >> 5);
            var dayOfWeek   = (flags >> 2) & 7;
            var advance     = (flags & 2) != 0;
            var addDay      = (flags & 1) != 0;
            int monthOfYear = reader.ReadCount();
            int dayOfMonth  = reader.ReadSignedCount();
            // The time of day is written as an offset for historical reasons.
            var ticksOfDay = reader.ReadOffset();

            return(new ZoneYearOffset(mode, monthOfYear, dayOfMonth, dayOfWeek, advance,
                                      new LocalTime(ticksOfDay.Ticks), addDay));
        }
        /// <summary>
        /// Reads a time zone from the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="id">The id.</param>
        /// <returns>The time zone.</returns>
        public static DateTimeZone Read(IDateTimeZoneReader reader, string id)
        {
            int size    = reader.ReadCount();
            var periods = new ZoneInterval[size];
            var start   = reader.ReadZoneIntervalTransition(null);

            for (int i = 0; i < size; i++)
            {
                var name      = reader.ReadString();
                var offset    = reader.ReadOffset();
                var savings   = reader.ReadOffset();
                var nextStart = reader.ReadZoneIntervalTransition(start);
                periods[i] = new ZoneInterval(name, start, nextStart, offset, savings);
                start      = nextStart;
            }
            var tailZone = reader.ReadByte() == 1 ? DaylightSavingsDateTimeZone.Read(reader, id + "-tail") : null;

            return(new PrecalculatedDateTimeZone(id, periods, tailZone));
        }
Exemple #4
0
        /// <summary>
        /// Reads a time zone from the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="id">The id.</param>
        /// <returns>The time zone.</returns>
        internal static DateTimeZone Read([Trusted][NotNull] IDateTimeZoneReader reader, [Trusted][NotNull] string id)
        {
            Preconditions.DebugCheckNotNull(reader, nameof(reader));
            Preconditions.DebugCheckNotNull(id, nameof(id));
            int size    = reader.ReadCount();
            var periods = new ZoneInterval[size];
            // It's not entirely clear why we don't just assume that the first zone interval always starts at Instant.BeforeMinValue
            // (given that we check that later) but we don't... and changing that now could cause compatibility issues.
            var start = reader.ReadZoneIntervalTransition(null);

            for (int i = 0; i < size; i++)
            {
                var name      = reader.ReadString();
                var offset    = reader.ReadOffset();
                var savings   = reader.ReadOffset();
                var nextStart = reader.ReadZoneIntervalTransition(start);
                periods[i] = new ZoneInterval(name, start, nextStart, offset, savings);
                start      = nextStart;
            }
            var tailZone = reader.ReadByte() == 1 ? DaylightSavingsDateTimeZone.Read(reader, id + "-tail") : null;

            return(new PrecalculatedDateTimeZone(id, periods, tailZone));
        }