use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_quarters_SMART.
@Test(dataProvider = "quarter")
public void test_parse_quarters_SMART(LocalDate date, int doq, int qoy) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral('-').appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral('-').appendValue(IsoFields.DAY_OF_QUARTER).toFormatter().withResolverStyle(ResolverStyle.SMART);
LocalDate parsed = LocalDate.parse(date.getYear() + "-" + qoy + "-" + doq, f);
assertEquals(parsed, date);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_parseLenientWeek_LENIENT.
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_LENIENT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':').appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_parseLenientWeek_SMART.
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':').appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(ResolverStyle.SMART);
if (smart) {
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
} else {
try {
LocalDate.parse(str, f);
fail("Should have failed");
} catch (DateTimeParseException ex) {
// expected
}
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TestDateTimeFormatter method test_withLocale_same.
@Test
public void test_withLocale_same() throws Exception {
DateTimeFormatter base = new DateTimeFormatterBuilder().appendLiteral("ONE").appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE).toFormatter(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
DateTimeFormatter test = base.withLocale(Locale.ENGLISH);
assertSame(test, base);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TestNonIsoFormatter method test_chronoNames.
@Test(dataProvider = "chrono_names")
public void test_chronoNames(Chronology chrono, Locale locale, String expected) {
DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendChronologyText(TextStyle.SHORT).toFormatter(locale);
String text = dtf.format(chrono.dateNow());
assertEquals(text, expected);
TemporalAccessor ta = dtf.parse(text);
Chronology cal = ta.query(TemporalQueries.chronology());
assertEquals(cal, chrono);
}
Aggregations