use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_wrongChrono.
@Test(expectedExceptions = DateTimeParseException.class)
public void test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_wrongChrono() {
ChronoLocalDateTime<?> cldt = ThaiBuddhistChronology.INSTANCE.dateNow().atTime(LocalTime.NOON);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(cldt)).toFormatter();
f.parse("1234567890");
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_parse_fromField_InstantSeconds_NanoOfSecond.
@Test
public void test_parse_fromField_InstantSeconds_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("86402.123456789");
Instant expected = Instant.ofEpochSecond(86402, 123456789);
assertEquals(acc.isSupported(INSTANT_SECONDS), 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(INSTANT_SECONDS), 86402L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
assertEquals(Instant.from(acc), expected);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_fieldResolvesToChronoLocalDate_noOverrideChrono_matches.
//-------------------------------------------------------------------------
@Test
public void test_fieldResolvesToChronoLocalDate_noOverrideChrono_matches() {
LocalDate ldt = LocalDate.of(2010, 6, 30);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(ldt)).toFormatter();
TemporalAccessor accessor = f.parse("1234567890");
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_withZone_parsedZone_noOverride.
@Test
public void test_withZone_parsedZone_noOverride() {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).appendZoneId().toFormatter();
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);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKLocalDate method factory_parse_formatter.
//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test
public void factory_parse_formatter() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d");
LocalDate test = LocalDate.parse("2010 12 3", f);
assertEquals(test, LocalDate.of(2010, 12, 3));
}
Aggregations