private static TzdbStreamData LoadDefaultDataSource()
            {
                var assembly = typeof(DefaultHolder).Assembly;

                using (Stream stream = assembly.GetManifestResourceStream("NodaTime.TimeZones.Tzdb.nzd"))
                {
                    return(TzdbStreamData.FromStream(stream));
                }
            }
Ejemplo n.º 2
0
        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"));
        }
 /// <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)));
 }