예제 #1
0
 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));
 }
예제 #2
0
 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);
 }
예제 #3
0
 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);
 }
예제 #4
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);
             }
         }
     }
 }
예제 #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);
                    }
                }
            }
        }
예제 #6
0
 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);
 }
예제 #7
0
 public void ParseDateTimeOfYear_emptyString()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize(string.Empty);
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseDateTimeOfYear(tokens, true));
 }
예제 #8
0
 /// <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;
 }
예제 #9
0
 public void ParseLink_tooFewWords_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("from");
     Assert.Throws<InvalidDataException>(() => parser.ParseLink(tokens));
 }
예제 #10
0
 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);
 }
예제 #11
0
 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();
 }
예제 #13
0
 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();
 }
예제 #15
0
 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));
 }
예제 #16
0
 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));
 }
예제 #17
0
 public void ParseZone_tooFewWords2_exception()
 {
     var parser = new TzdbZoneInfoParser();
     var tokens = Tokens.Tokenize("2:00");
     Assert.Throws(typeof(InvalidDataException), () => parser.ParseZone(string.Empty, tokens));
 }
예제 #18
0
 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));
 }
예제 #19
0
 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));
 }
예제 #20
0
 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);
 }
예제 #21
0
 /// <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();            
 }