use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDateTime_overrideChrono_wrongChrono.
@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDateTime_overrideChrono_wrongChrono() {
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
f = f.withChronology(MinguoChronology.INSTANCE);
f.parse("1234567890");
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveClockHourOfDay.
@Test(dataProvider = "resolveClockHourOfDay")
public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter();
if (expectedHour != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
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.DateTimeFormatter 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.DateTimeFormatter 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.DateTimeFormatter 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);
}
Aggregations