コード例 #1
0
        private static void ReadZone1970Locations(DateTimeZoneReader reader)
        {
            var count = reader.ReadCount();

            Console.WriteLine($"  Entries: {count}");
            for (int i = 0; i < count; i++)
            {
                int           latitudeSeconds  = reader.ReadSignedCount();
                int           longitudeSeconds = reader.ReadSignedCount();
                int           countryCount     = reader.ReadCount();
                StringBuilder countries        = new StringBuilder();
                for (int j = 0; j < countryCount; j++)
                {
                    countries.Append($"{reader.ReadString()} ({reader.ReadString()}), ");
                }
                if (countries.Length > 0)
                {
                    // Remove the trailing comma+space.
                    countries.Length -= 2;
                }
                string zoneId  = reader.ReadString();
                string comment = reader.ReadString();
                Console.WriteLine($"  Lat seconds: {latitudeSeconds}; long seconds: {longitudeSeconds}: countries: [{countries}]; id: {zoneId}; comment: {comment}");
            }
        }
コード例 #2
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");
            }
        }
コード例 #3
0
        private static void ReadMap(DateTimeZoneReader reader)
        {
            int count = reader.ReadCount();

            Console.WriteLine($"  Entries: {count}");
            for (int i = 0; i < count; i++)
            {
                string key   = reader.ReadString();
                string value = reader.ReadString();
                Console.WriteLine($"    {key} -> {value}");
            }
        }
コード例 #4
0
        private static string[] ReadStringPool(DateTimeZoneReader reader)
        {
            int count = reader.ReadCount();

            Console.WriteLine($"  String pool contains {count} entries");
            var stringPool = new string[count];

            for (int i = 0; i < count; i++)
            {
                stringPool[i] = reader.ReadString();
            }
            return(stringPool);
        }
コード例 #5
0
        private static void ReadZoneLocations(DateTimeZoneReader reader)
        {
            var count = reader.ReadCount();

            Console.WriteLine($"  Entries: {count}");
            for (int i = 0; i < count; i++)
            {
                int    latitudeSeconds  = reader.ReadSignedCount();
                int    longitudeSeconds = reader.ReadSignedCount();
                string countryName      = reader.ReadString();
                string countryCode      = reader.ReadString();
                string zoneId           = reader.ReadString();
                string comment          = reader.ReadString();
                Console.WriteLine($"  Lat seconds: {latitudeSeconds}; long seconds: {longitudeSeconds}: country: {countryName} ({countryCode}); id: {zoneId}; comment: {comment}");
            }
        }
コード例 #6
0
        public void ReadCount_OutOfRange()
        {
            // Int32.MaxValue + 1 (as a uint) is 10000000_00000000_00000000_00000000
            // So only bit 31 is set.
            // Divided into 7 bit chunks (reverse order), with top bit set for continuation, this is:
            // 10000000 - bits 0-6
            // 10000000 - bits 7-13
            // 10000000 - bits 14-20
            // 10000000 - bits 21-27
            // 00001000 - bits 28-34
            byte[] data   = new byte[] { 0x80, 0x80, 0x80, 0x80, 0b0000_1000 };
            var    stream = new MemoryStream(data);
            var    reader = new DateTimeZoneReader(stream, null);

            Assert.Throws <InvalidNodaDataException>(() => reader.ReadCount());
        }