Пример #1
0
        public void ParseLink_tooFewWords_exception()
        {
            var parser = new TzdbZoneInfoParser();
            var tokens = Tokens.Tokenize("from");

            Assert.Throws <InvalidDataException>(() => parser.ParseLink(tokens));
        }
Пример #2
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));
        }
Пример #3
0
        public void ParseDateTimeOfYear_emptyString()
        {
            var parser = new TzdbZoneInfoParser();
            var tokens = Tokens.Tokenize(string.Empty);

            Assert.Throws(typeof(InvalidDataException), () => parser.ParseDateTimeOfYear(tokens, true));
        }
Пример #4
0
        public void ParseLink_emptyString_exception()
        {
            var parser = new TzdbZoneInfoParser();
            var tokens = Tokens.Tokenize(string.Empty);

            Assert.Throws(typeof(InvalidDataException), () => parser.ParseLink(tokens));
        }
Пример #5
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));
        }
Пример #6
0
 public void ParseMonth_months()
 {
     for (int i = 0; i < MonthNames.Length; i++)
     {
         var month = MonthNames[i];
         Assert.AreEqual(i + 1, TzdbZoneInfoParser.ParseMonth(month));
     }
 }
Пример #7
0
        public void ParseZone_optionalRule()
        {
            var parser   = new TzdbZoneInfoParser();
            var tokens   = Tokens.Tokenize("2:00 - P%sT");
            var expected = new ZoneLine("", ToOffset(2, 0), null, "P%sT", int.MaxValue, TzdbZoneInfoParser.StartOfYearZoneOffset);

            Assert.AreEqual(expected, parser.ParseZone("", tokens));
        }
Пример #8
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));
        }
Пример #9
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));
        }
Пример #10
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));
        }
Пример #11
0
 public void ParseMonth_longMonthNames()
 {
     for (int i = 1; i < 12; i++)
     {
         var month = new DateTime(2000, i, 1).ToString("MMMM", CultureInfo.InvariantCulture);
         Assert.AreEqual(i, TzdbZoneInfoParser.ParseMonth(month));
     }
 }
Пример #12
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));
        }
Пример #13
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);
        }
Пример #14
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));
        }
Пример #15
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);
        }
Пример #16
0
        public void ParseDateTimeOfYear_onBefore()
        {
            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, false, new LocalTime(2, 0));

            Assert.AreEqual(expected, actual);
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
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);
        }
Пример #20
0
        public void ParseMonth_invalidMonth_default()
        {
            const string month = "Able";

            Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(month));
        }
Пример #21
0
 public void ParseMonth_nullOrEmpty()
 {
     Assert.Throws <ArgumentException>(() => TzdbZoneInfoParser.ParseMonth(""));
     Assert.Throws <ArgumentException>(() => TzdbZoneInfoParser.ParseMonth(null !));
 }
Пример #22
0
 public void ParseMonth_invalidMonth_default()
 {
     Assert.Throws <InvalidDataException>(() => TzdbZoneInfoParser.ParseMonth("Able"));
 }
Пример #23
0
 public void ParseMonth_emptyString_default()
 {
     Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(string.Empty));
 }
Пример #24
0
        public void ParseMonth_nullArgument_default()
        {
            string month = null;

            Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(month));
        }
 public void Setup()
 {
     Parser = new TzdbZoneInfoParser();
 }