public void Format_NoValidPattern() { var pattern = new CompositePatternBuilder <LocalDate> { { LocalDatePattern.Iso, _ => false }, { LocalDatePattern.CreateWithInvariantCulture("yyyy"), _ => false }, }.Build(); Assert.Throws <FormatException>(() => pattern.Format(new LocalDate(2017, 1, 1))); }
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); }