Exemple #1
0
        public void Serialization()
        {
            var location = new TzdbZoneLocation(
                60 * 3600 + 15 * 60 + 5,
                100 * 3600 + 30 * 60 + 10,
                "Country name",
                "CO",
                "Etc/MadeUpZone",
                "Comment");

            var stream = new MemoryStream();
            var writer = new DateTimeZoneWriter(stream, null);

            location.Write(writer);
            stream.Position = 0;

            var reader    = new DateTimeZoneReader(stream, null);
            var location2 = TzdbZoneLocation.Read(reader);

            Assert.AreEqual(60.25 + 5.0 / 3600, location2.Latitude, 0.000001);
            Assert.AreEqual(100.5 + 10.0 / 3600, location2.Longitude, 0.000001);
            Assert.AreEqual("Country name", location2.CountryName);
            Assert.AreEqual("CO", location2.CountryCode);
            Assert.AreEqual("Etc/MadeUpZone", location2.ZoneId);
            Assert.AreEqual("Comment", location2.Comment);
        }
Exemple #2
0
 internal void HandleZoneLocationsField(TzdbStreamField field)
 {
     CheckSingleField(field, zoneLocations);
     CheckStringPoolPresence(field);
     using (var stream = field.CreateStream())
     {
         var reader = new DateTimeZoneReader(stream, stringPool);
         var count  = reader.ReadCount();
         var array  = new TzdbZoneLocation[count];
         for (int i = 0; i < count; i++)
         {
             array[i] = TzdbZoneLocation.Read(reader);
         }
         zoneLocations = array;
     }
 }
Exemple #3
0
        public void ReadInvalid()
        {
            var stream = new MemoryStream();
            var writer = new DateTimeZoneWriter(stream, null);

            // This is invalid
            writer.WriteSignedCount(90 * 3600 + 1);
            writer.WriteSignedCount(0);
            writer.WriteString("name");
            writer.WriteString("co");
            writer.WriteString("Europe/Somewhere");
            writer.WriteString("");
            stream.Position = 0;
            var reader = new DateTimeZoneReader(stream, null);

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