Esempio n. 1
0
        public void HasMoreData_Buffers()
        {
            var stream = new MemoryStream(new byte[] { 1, 2 });
            var reader = new DateTimeZoneReader(stream, null);

            // HasMoreData reads a byte and buffers it
            Assert.AreEqual(0, stream.Position);
            Assert.IsTrue(reader.HasMoreData);
            Assert.AreEqual(1, stream.Position);
            Assert.IsTrue(reader.HasMoreData);
            Assert.AreEqual(1, stream.Position);

            // Consume the buffered byte
            Assert.AreEqual((byte)1, reader.ReadByte());
            Assert.AreEqual(1, stream.Position);

            // HasMoreData reads the next byte
            Assert.IsTrue(reader.HasMoreData);
            Assert.AreEqual(2, stream.Position);
            Assert.IsTrue(reader.HasMoreData);
            Assert.AreEqual(2, stream.Position);

            // Consume the buffered byte
            Assert.AreEqual((byte)2, reader.ReadByte());
            Assert.AreEqual(2, stream.Position);

            // No more data
            Assert.IsFalse(reader.HasMoreData);
        }
Esempio n. 2
0
        public void ReadByte_NotEnoughData()
        {
            byte[] data   = new byte[] { 0x05 };
            var    stream = new MemoryStream(data);
            var    reader = new DateTimeZoneReader(stream, null);

            // Just check we can read the first byte, then fail on the second
            Assert.AreEqual((byte)5, reader.ReadByte());
            Assert.Throws <InvalidNodaDataException>(() => reader.ReadByte());
        }
Esempio n. 3
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");
            }
        }
Esempio n. 4
0
        private static void ReadTimeZone(DateTimeZoneReader reader)
        {
            Console.WriteLine($"  ID: {reader.ReadString()}");
            var type = (DateTimeZoneWriter.DateTimeZoneType)reader.ReadByte();

            Console.WriteLine($"  Type: {type}");
            switch (type)
            {
            case DateTimeZoneWriter.DateTimeZoneType.Fixed:
                ReadFixedTimeZone(reader);
                break;

            case DateTimeZoneWriter.DateTimeZoneType.Precalculated:
                ReadPrecalculatedTimeZone(reader);
                break;

            default:
                Console.WriteLine("  (Unknown time zone type)");
                break;
            }
        }