use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_parse_fromField_SecondOfMinute_NanoOfSecond.
@Test
public void test_parse_fromField_SecondOfMinute_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendValue(SECOND_OF_MINUTE).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("32.123456789");
assertEquals(acc.isSupported(SECOND_OF_MINUTE), 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_MINUTE), 32L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveAmPm.
@Test(dataProvider = "resolveAmPm")
public void test_resolveAmPm(ResolverStyle style, long value, Integer expectedValue) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(AMPM_OF_DAY).toFormatter();
if (expectedValue != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(AMPM_OF_DAY), true);
assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue());
} 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_resolveThreeToDate.
@Test(dataProvider = "resolveThreeToDate")
public void test_resolveThreeToDate(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3, LocalDate expectedDate) {
String str = value1 + " " + value2 + " " + value3;
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).appendLiteral(' ').appendValue(field2).appendLiteral(' ').appendValue(field3).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDate_noOverrideChrono_wrongChrono.
@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDate_noOverrideChrono_wrongChrono() {
ChronoLocalDate cld = ThaiBuddhistChronology.INSTANCE.dateNow();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cld)).toFormatter();
f.parse("1234567890");
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_withZone_parsedZone_override.
@Test
public void test_withZone_parsedZone_override() {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendZoneId().toFormatter();
f = f.withZone(EUROPE_ATHENS);
TemporalAccessor accessor = f.parse("Europe/Paris");
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.query(TemporalQueries.zoneId()), EUROPE_PARIS);
}
Aggregations