Ejemplo n.º 1
0
        private static void ReadPrecalculatedTimeZone(DateTimeZoneReader reader)
        {
            int size = reader.ReadCount();

            Console.WriteLine($"  Precalculated intervals: {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);
                Console.WriteLine(Invariant($"  {start:yyyy-MM-dd'T'HH:mm:ss} - {nextStart:yyyy-MM-dd'T'HH:mm:ss}; wall offset: {offset}; savings: {savings}; name: {name}"));
                start = nextStart;
            }
            if (reader.ReadByte() == 1)
            {
                Offset         standardOffset     = reader.ReadOffset();
                string         standardName       = reader.ReadString();
                ZoneYearOffset standardYearOffset = ZoneYearOffset.Read(reader);
                string         daylightName       = reader.ReadString();
                ZoneYearOffset daylightYearOffset = ZoneYearOffset.Read(reader);
                Offset         savings            = reader.ReadOffset();
                Console.WriteLine("  Tail zone:");
                Console.WriteLine($"    Standard time: {standardYearOffset}; offset: {standardOffset}; name: {standardName}");
                Console.WriteLine($"    Daylight time: {daylightYearOffset}; offset: {standardOffset + savings}; name: {daylightName}");
            }
            else
            {
                Console.WriteLine("  No tail zone");
            }
        }
Ejemplo n.º 2
0
        public void ReadZoneIntervalTransition_InvalidMarkerValue()
        {
            byte[] data   = new byte[] { 4, 0, 0, 0, 0, 0 }; // Marker value of 4 (followed by 0s to check that it's not just out of data)
            var    stream = new MemoryStream(data);
            var    reader = new DateTimeZoneReader(stream, null);

            Assert.Throws <InvalidNodaDataException>(() => reader.ReadZoneIntervalTransition(previous: NodaConstants.UnixEpoch));
        }
Ejemplo n.º 3
0
        public void ReadZoneIntervalTransition_NoPreviousValue()
        {
            // Count value between 1 << 7 and 1 << 21 (followed by 0s to check that it's not just out of data)
            byte[] data   = new byte[] { 0xff, 0x7f, 0, 0, 0, 0 };
            var    stream = new MemoryStream(data);
            var    reader = new DateTimeZoneReader(stream, null);

            Assert.Throws <InvalidNodaDataException>(() => reader.ReadZoneIntervalTransition(previous: null));

            // Validate that when we *do* provide a previous value, it doesn't throw
            stream.Position = 0;
            reader          = new DateTimeZoneReader(stream, null);
            reader.ReadZoneIntervalTransition(previous: NodaConstants.UnixEpoch);
        }