public void ParseLink_tooFewWords_exception() { var parser = new TzdbZoneInfoParser(); var tokens = Tokens.Tokenize("from"); Assert.Throws <InvalidDataException>(() => parser.ParseLink(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 ParseDateTimeOfYear_emptyString() { var parser = new TzdbZoneInfoParser(); var tokens = Tokens.Tokenize(string.Empty); Assert.Throws(typeof(InvalidDataException), () => parser.ParseDateTimeOfYear(tokens, true)); }
public void ParseLink_emptyString_exception() { var parser = new TzdbZoneInfoParser(); var tokens = Tokens.Tokenize(string.Empty); Assert.Throws(typeof(InvalidDataException), () => parser.ParseLink(tokens)); }
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)); }
public void ParseMonth_months() { for (int i = 0; i < MonthNames.Length; i++) { var month = MonthNames[i]; Assert.AreEqual(i + 1, TzdbZoneInfoParser.ParseMonth(month)); } }
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)); }
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_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 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 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)); } }
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)); }
/// <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 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 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_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); }
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 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 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); }
public void ParseMonth_invalidMonth_default() { const string month = "Able"; Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(month)); }
public void ParseMonth_nullOrEmpty() { Assert.Throws <ArgumentException>(() => TzdbZoneInfoParser.ParseMonth("")); Assert.Throws <ArgumentException>(() => TzdbZoneInfoParser.ParseMonth(null !)); }
public void ParseMonth_invalidMonth_default() { Assert.Throws <InvalidDataException>(() => TzdbZoneInfoParser.ParseMonth("Able")); }
public void ParseMonth_emptyString_default() { Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(string.Empty)); }
public void ParseMonth_nullArgument_default() { string month = null; Assert.AreEqual(0, TzdbZoneInfoParser.ParseMonth(month)); }
public void Setup() { Parser = new TzdbZoneInfoParser(); }