use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_ignoreCrossCheck.
@Test
public void test_resolverFields_ignoreCrossCheck() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(DAY_OF_YEAR).appendLiteral('-').appendValue(DAY_OF_WEEK).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
try {
// wrong day-of-week
base.parse("2012-321-1", LocalDate::from);
fail();
} catch (DateTimeException ex) {
// expected, should fail in cross-check of day-of-week
}
// ignored wrong day-of-week
LocalDate parsed = f.parse("2012-321-1", LocalDate::from);
assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_format_withChronology_nonChronoFieldMapLink.
@Test
public void test_format_withChronology_nonChronoFieldMapLink() {
TemporalAccessor temporal = new TemporalAccessor() {
@Override
public boolean isSupported(TemporalField field) {
return field == IsoFields.WEEK_BASED_YEAR;
}
@Override
public long getLong(TemporalField field) {
if (field == IsoFields.WEEK_BASED_YEAR) {
return 2345;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
};
DateTimeFormatter test = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR, 4).toFormatter(Locale.ENGLISH).withChronology(IsoChronology.INSTANCE);
String result = test.format(temporal);
assertEquals(result, "2345");
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_listOfOneNull.
@Test
public void test_resolverFields_listOfOneNull() throws Exception {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).toFormatter().withResolverFields((TemporalField) null);
TemporalAccessor parsed = f.parse("2012");
// not in the list of resolverFields
assertEquals(parsed.isSupported(YEAR), false);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKInstantPrinterParser method test_print_digits.
@Test(dataProvider = "printDigits")
public void test_print_digits(int fractionalDigits, long instantSecs, int nano, String expected) {
Instant instant = Instant.ofEpochSecond(instantSecs, nano);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(fractionalDigits).toFormatter();
assertEquals(f.format(instant), expected);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKInstantPrinterParser method test_parse_leapSecond.
@Test
public void test_parse_leapSecond() {
Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter();
for (ResolverStyle style : ResolverStyle.values()) {
TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z");
assertEquals(parsed.query(Instant::from), expected);
assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO);
assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE);
}
}
Aggregations