public void ParseDateTimeOfYear_missingOn_invalidForRule()
 {
     var parser = new TzdbZoneInfoParser();
     const string text = "Mar";
     var tokens = Tokens.Tokenize(text);
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseDateTimeOfYear(tokens, true));
 }
 public void ParseDateTimeOfYear_missingOn_validForZone()
 {
     var parser = new TzdbZoneInfoParser();
     const string text = "Mar";
     var tokens = Tokens.Tokenize(text);
     var actual = parser.ParseDateTimeOfYear(tokens, false);
     var expected = new ZoneYearOffset(TransitionMode.Wall, 3, 1, 0, false, LocalTime.Midnight);
     Assert.AreEqual(expected, actual);
 }
 public void ParseDateTimeOfYear_onAfter()
 {
     var parser = new TzdbZoneInfoParser();
     const string text = "Mar Tue>=14 2:00";
     var tokens = Tokens.Tokenize(text);
     var actual = parser.ParseDateTimeOfYear(tokens, true);
     var expected = new ZoneYearOffset(TransitionMode.Wall, 3, 14, (int)IsoDayOfWeek.Tuesday, true, new LocalTime(2, 0));
     Assert.AreEqual(expected, actual);
 }
 private void LoadZoneFiles(FileSource source, TzdbDatabase database)
 {
     var tzdbParser = new TzdbZoneInfoParser();
     foreach (var file in ZoneFiles)
     {
         if (source.Contains(file))
         {
             log?.WriteLine("Parsing file {0} . . .", file);
             using (var stream = source.Open(file))
             {
                 tzdbParser.Parse(stream, database);
             }
         }
     }
 }
示例#5
0
        private void LoadZoneFiles(FileSource source, TzdbDatabase database)
        {
            var tzdbParser = new TzdbZoneInfoParser();

            foreach (var file in ZoneFiles)
            {
                if (source.Contains(file))
                {
                    log?.WriteLine("Parsing file {0} . . .", file);
                    using (var stream = source.Open(file))
                    {
                        tzdbParser.Parse(stream, database);
                    }
                }
            }
        }
 public void ParseLink_simple()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("from to");
     var actual = parser.ParseLink(tokens);
     var expected = Tuple.Create("from", "to");
     Assert.AreEqual(expected, actual);
 }
 public void ParseDateTimeOfYear_emptyString()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize(string.Empty);
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseDateTimeOfYear(tokens, true));
 }
 /// <summary>
 /// Helper method to create a database and call Parse with the given text.
 /// </summary>
 private TzdbDatabase ParseText(string line)
 {
     var parser = new TzdbZoneInfoParser();
     var database = new TzdbDatabase("version");
     parser.Parse(new StringReader(line), database);
     return database;
 }
 public void ParseLink_tooFewWords_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("from");
     Assert.Throws<InvalidDataException>(() => parser.ParseLink(tokens));
 }
 public void Parse_2400_Last()
 {
     var parser = new TzdbZoneInfoParser();
     const string text = "Mar lastSun 24:00";
     var tokens = Tokens.Tokenize(text);
     var actual = parser.ParseDateTimeOfYear(tokens, true);
     var expected = new ZoneYearOffset(TransitionMode.Wall, 3, -1, (int)IsoDayOfWeek.Sunday, false, LocalTime.Midnight, true);
     Assert.AreEqual(expected, actual);
 }
 public void ParseZone_badOffset_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("asd US P%sT 1969 Mar 23 14:53:27.856s");
     Assert.Throws(typeof(FormatException), () => parser.ParseZone(string.Empty, tokens));
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="TzdbZoneInfoCompiler" /> class.
 /// </summary>
 /// <param name="log">The log to send all output messages to.</param>
 internal TzdbZoneInfoCompiler()
 {
     tzdbParser = new TzdbZoneInfoParser();
 }
 public void ParseLink_emptyString_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize(string.Empty);
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseLink(tokens));
 }
 public void Setup()
 {
     Parser = new TzdbZoneInfoParser();
 }
 public void ParseZone_withYearMonthDayTimeZone()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00 US P%sT 1969 Mar 23 14:53:27.856s");
     var expected = new ZoneLine(string.Empty, ToOffset(2, 0), "US", "P%sT", 1969, new ZoneYearOffset(TransitionMode.Standard, 3, 23, 0, false, new LocalTime(14, 53, 27, 856)));
     Assert.AreEqual(expected, parser.ParseZone(string.Empty, tokens));
 }
 public void ParseZone_withYear()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00 US P%sT 1969");
     var expected = new ZoneLine(string.Empty, ToOffset(2, 0), "US", "P%sT", 1969, new ZoneYearOffset(TransitionMode.Wall, 1, 1, 0, false, LocalTime.Midnight));
     Assert.AreEqual(expected, parser.ParseZone(string.Empty, tokens));
 }
 public void ParseZone_tooFewWords2_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00");
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseZone(string.Empty, tokens));
 }
 public void ParseZone_simple()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00 US P%sT");
     var expected = new ZoneLine(string.Empty, ToOffset(2, 0), "US", "P%sT", int.MaxValue, ZoneYearOffset.StartOfYear);
     Assert.AreEqual(expected, parser.ParseZone(string.Empty, tokens));
 }
 public void ParseZone_withDayOfWeek()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00 US P%sT 1969 Mar lastSun");
     var expected = new ZoneLine(string.Empty, ToOffset(2, 0), "US", "P%sT", 1969, new ZoneYearOffset(TransitionMode.Wall, 3, -1, (int) IsoDayOfWeek.Sunday, false, LocalTime.Midnight));
     Assert.AreEqual(expected, parser.ParseZone(string.Empty, tokens));
 }
 public void Parse_2400_FromDay_AtMost_Wednesday()
 {
     var parser = new TzdbZoneInfoParser();
     const string text = "Apr Wed<=14  24:00";
     var tokens = Tokens.Tokenize(text);
     var rule = parser.ParseDateTimeOfYear(tokens, true);
     var actual = rule.GetOccurrenceForYear(2012);
     var expected = new LocalDateTime(2012, 4, 12, 0, 0).ToLocalInstant();
     Assert.AreEqual(expected, actual);
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="TzdbZoneInfoCompiler" /> class.
 /// </summary>
 internal TzdbZoneInfoCompiler()
 {
     tzdbParser = new TzdbZoneInfoParser();
 }
示例#22
0
 private static List<DateTimeZone> LoadTzSources(IEnumerable<byte[]> sources)
 {
     var parser = new TzdbZoneInfoParser();
     var database = new TzdbDatabase(version: "ignored");
     foreach (var source in sources)
     {
         parser.Parse(new MemoryStream(source), database);
     }
     return database.GenerateDateTimeZones()
         .Concat(database.Aliases.Keys.Select(database.GenerateDateTimeZone))
         .ToList();            
 }