use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method factory_parse_formatter.
//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test
public void factory_parse_formatter() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s VV");
ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveFourToDate.
@Test(dataProvider = "resolveFourToDate")
public void test_resolveFourToDate(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField field3, long value3, TemporalField field4, long value4, LocalDate expectedDate) {
String str = value1 + " " + value2 + " " + value3 + " " + value4;
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).appendLiteral(' ').appendValue(field2).appendLiteral(' ').appendValue(field3).appendLiteral(' ').appendValue(field4).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_fieldResolvesToChronoZonedDateTime_overrideZone_matches.
@Test
public void test_fieldResolvesToChronoZonedDateTime_overrideZone_matches() {
ZonedDateTime zdt = ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, EUROPE_PARIS);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(new ResolvingField(zdt)).toFormatter();
f = f.withZone(EUROPE_PARIS);
assertEquals(f.parse("1234567890", ZonedDateTime::from), zdt);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_resolveTwoToField.
@Test(dataProvider = "resolveTwoToField")
public void test_resolveTwoToField(TemporalField field1, long value1, TemporalField field2, long value2, TemporalField expectedField1, Long expectedValue1, TemporalField expectedField2, Long expectedValue2) {
String str = value1 + " " + value2;
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).appendLiteral(' ').appendValue(field2).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
if (expectedField1 != null) {
assertEquals(accessor.isSupported(expectedField1), true);
assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
}
if (expectedField2 != null) {
assertEquals(accessor.isSupported(expectedField2), true);
assertEquals(accessor.getLong(expectedField2), expectedValue2.longValue());
}
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_withZone_noOverride.
//-----------------------------------------------------------------------
// SPEC: DateTimeFormatter.withZone()
@Test
public void test_withZone_noOverride() {
DateTimeFormatter f = new DateTimeFormatterBuilder().parseDefaulting(EPOCH_DAY, 2).toFormatter();
TemporalAccessor accessor = f.parse("");
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(1970, 1, 3));
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.query(TemporalQueries.zoneId()), null);
}
Aggregations