public void Parse() { var pattern = new CompositePatternBuilder <LocalDate> { { LocalDatePattern.Iso, _ => true }, { LocalDatePattern.CreateWithInvariantCulture("yyyy"), _ => false }, }.Build(); Assert.IsTrue(pattern.Parse("2017-03-20").Success); Assert.IsFalse(pattern.Parse("2017-03").Success); Assert.IsTrue(pattern.Parse("2017").Success); }
public void IsoPattern(string text) { // We assert that the text round-trips. If it does, it's // reasonable to assume it parsed correctly... var shortPattern = LocalDateTimePattern.CreateWithInvariantCulture("uuuu'-'MM'-'dd'T'HH':'mm"); var pattern = new CompositePatternBuilder <LocalDateTime> { { LocalDateTimePattern.ExtendedIso, _ => true }, { shortPattern, ldt => ldt.Second == 0 && ldt.NanosecondOfSecond == 0 } }.Build(); var value = pattern.Parse(text).Value; string formatted = pattern.Format(value); Assert.AreEqual(text, formatted); }