use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveFourToDateTime.
@Test(dataProvider = "resolveFourToTime")
public void test_resolveFourToDateTime(ResolverStyle style, long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30).parseDefaulting(HOUR_OF_DAY, hour).parseDefaulting(MINUTE_OF_HOUR, min).parseDefaulting(SECOND_OF_MINUTE, sec).parseDefaulting(NANO_OF_SECOND, nano).toFormatter();
ResolverStyle[] styles = (style != null ? new ResolverStyle[] { style } : ResolverStyle.values());
if (expectedTime != null && excessPeriod != null) {
LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
for (ResolverStyle s : styles) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
}
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveSecondOfDay.
@Test(dataProvider = "resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
if (expectedSecond != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_parse_fromField_SecondOfDay.
// SPEC: ChronoField.SECOND_OF_DAY
@Test
public void test_parse_fromField_SecondOfDay() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
TemporalAccessor acc = fmt.parse("864");
assertEquals(acc.isSupported(SECOND_OF_DAY), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_withChronology_parsedChronology_override.
@Test
public void test_withChronology_parsedChronology_override() {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendChronologyId().toFormatter();
f = f.withChronology(MinguoChronology.INSTANCE);
TemporalAccessor accessor = f.parse("ThaiBuddhist");
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.query(TemporalQueries.chronology()), ThaiBuddhistChronology.INSTANCE);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveOneToTime.
@Test(dataProvider = "resolveOneToTime")
public void test_resolveOneToTime(TemporalField field1, long value1, LocalTime expectedTime) {
String str = Long.toString(value1);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
}
Aggregations