use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_selectOneDateResolveYD.
@Test
public void test_resolverFields_selectOneDateResolveYD() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter();
DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR);
Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR));
// Use set.equals(); testNG comparison of Collections is ordered
assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields());
try {
// wrong month/day-of-month
base.parse("2012-6-30-321", LocalDate::from);
fail();
} catch (DateTimeException ex) {
// expected, fails as it produces two different dates
}
// ignored month/day-of-month
LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from);
assertEquals(parsed, LocalDate.of(2012, 11, 16));
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_listOfOneMatching.
@Test
public void test_resolverFields_listOfOneMatching() throws Exception {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).toFormatter().withResolverFields(YEAR);
TemporalAccessor parsed = f.parse("2012");
assertEquals(parsed.isSupported(YEAR), true);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_resolverFields_listOfOneNotMatching.
@Test
public void test_resolverFields_listOfOneNotMatching() throws Exception {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).toFormatter().withResolverFields(MONTH_OF_YEAR);
TemporalAccessor parsed = f.parse("2012");
// not in the list of resolverFields
assertEquals(parsed.isSupported(YEAR), false);
assertEquals(parsed.isSupported(MONTH_OF_YEAR), false);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoy_strict.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoy_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(woyField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.getYear(), 2012);
assertEquals(date.get(woyField), 0);
assertEquals(date.get(DAY_OF_WEEK), 1);
} catch (DateTimeException ex) {
// expected
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWom.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(womField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " ::" + str + "::" + i);
date = date.plusDays(1);
}
}
Aggregations