コード例 #1
0
ファイル: TzdbStreamDataTest.cs プロジェクト: jskeet/nodatime
        public void InvalidVersion()
        {
            // It's hard to create a stream that's valid apart from the version, so we'll just
            // give one with an invalid version and check that it looks like the right message.
            var stream    = new MemoryStream(new byte[] { 0, 0, 0, 1 });
            var exception = Assert.Throws <InvalidNodaDataException>(() => TzdbStreamData.FromStream(stream));

            Assert.IsTrue(exception.Message.Contains("version"));
        }
コード例 #2
0
            private static TzdbStreamData LoadDefaultDataSource()
            {
                var assembly = typeof(DefaultHolder).Assembly;

                using (Stream stream = assembly.GetManifestResourceStream("NodaTime.TimeZones.Tzdb.nzd"))
                {
                    return(TzdbStreamData.FromStream(stream));
                }
            }
コード例 #3
0
 internal TzdbDateTimeZoneSource(TzdbStreamData source)
 {
     Preconditions.CheckNotNull(source, nameof(source));
     this.source = source;
     Aliases     = CanonicalIdMap
                   .Where(pair => pair.Key != pair.Value)
                   .OrderBy(pair => pair.Key, StringComparer.Ordinal)
                   .ToLookup(pair => pair.Value, pair => pair.Key);
     version = source.TzdbVersion + " (mapping: " + source.WindowsMapping.Version + ")";
 }
コード例 #4
0
 internal TzdbDateTimeZoneSource(TzdbStreamData source)
 {
     Preconditions.CheckNotNull(source, nameof(source));
     this.source = source;
     Aliases     = CanonicalIdMap
                   .Where(pair => pair.Key != pair.Value)
                   .OrderBy(pair => pair.Key, StringComparer.Ordinal)
                   .ToLookup(pair => pair.Value, pair => pair.Key);
     version         = $"{source.TzdbVersion} (mapping: {source.WindowsMapping.Version})";
     tzdbToWindowsId = new Lazy <IReadOnlyDictionary <string, string> >(BuildTzdbToWindowsIdMap, LazyThreadSafetyMode.ExecutionAndPublication);
     windowsToTzdbId = new Lazy <IReadOnlyDictionary <string, string> >(BuildWindowsToTzdbId, LazyThreadSafetyMode.ExecutionAndPublication);
 }
コード例 #5
0
        private TzdbDateTimeZoneSource([NotNull] TzdbStreamData source)
        {
            Preconditions.CheckNotNull(source, nameof(source));
            this.source    = source;
            CanonicalIdMap = new NodaReadOnlyDictionary <string, string>(source.TzdbIdMap);
            Aliases        = CanonicalIdMap
                             .Where(pair => pair.Key != pair.Value)
                             .OrderBy(pair => pair.Key, StringComparer.Ordinal)
                             .ToLookup(pair => pair.Value, pair => pair.Key);
            version = source.TzdbVersion + " (mapping: " + source.WindowsMapping.Version + ")";
            var originalZoneLocations = source.ZoneLocations;

            ZoneLocations = originalZoneLocations == null ? null : new ReadOnlyCollection <TzdbZoneLocation>(originalZoneLocations);
            var originalZone1970Locations = source.Zone1970Locations;

            Zone1970Locations = originalZone1970Locations == null ? null : new ReadOnlyCollection <TzdbZone1970Location>(originalZone1970Locations);
        }
コード例 #6
0
 private TzdbDateTimeZoneSource([NotNull] TzdbStreamData source)
 {
     Preconditions.CheckNotNull(source, nameof(source));
     this.source = source;
     CanonicalIdMap = new NodaReadOnlyDictionary<string, string>(source.TzdbIdMap);
     Aliases = CanonicalIdMap
         .Where(pair => pair.Key != pair.Value)
         .OrderBy(pair => pair.Key, StringComparer.Ordinal)
         .ToLookup(pair => pair.Value, pair => pair.Key);
     version = source.TzdbVersion + " (mapping: " + source.WindowsMapping.Version + ")";
     var originalZoneLocations = source.ZoneLocations;
     ZoneLocations = originalZoneLocations == null ? null : new ReadOnlyCollection<TzdbZoneLocation>(originalZoneLocations);
     var originalZone1970Locations = source.Zone1970Locations;
     Zone1970Locations = originalZone1970Locations == null ? null : new ReadOnlyCollection<TzdbZone1970Location>(originalZone1970Locations);
 }
コード例 #7
0
 /// <summary>
 /// Creates an instance from a stream in the custom Noda Time format. The stream must be readable.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The stream is not closed by this method, but will be read from
 /// without rewinding. A successful call will read the stream to the end.
 /// </para>
 /// <para>
 /// See the user guide for instructions on how to generate an updated time zone database file from a copy of the
 /// (textual) tz database.
 /// </para>
 /// </remarks>
 /// <param name="stream">The stream containing time zone data</param>
 /// <returns>A <c>TzdbDateTimeZoneSource</c> providing information from the given stream.</returns>
 /// <exception cref="InvalidNodaDataException">The stream contains invalid time zone data, or data which cannot
 /// be read by this version of Noda Time.</exception>
 /// <exception cref="IOException">Reading from the stream failed.</exception>
 /// <exception cref="InvalidOperationException">The supplied stream doesn't support reading.</exception>
 public static TzdbDateTimeZoneSource FromStream([NotNull] Stream stream)
 {
     Preconditions.CheckNotNull(stream, nameof(stream));
     return(new TzdbDateTimeZoneSource(TzdbStreamData.FromStream(stream)));
 }
コード例 #8
0
ファイル: TzdbStreamDataTest.cs プロジェクト: jskeet/nodatime
        public void Minimal()
        {
            var data = new TzdbStreamData(CreateMinimalBuilder());

            Assert.NotNull(data.TzdbVersion);
        }