use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_withLocale.
//-----------------------------------------------------------------------
@Test
public void test_withLocale() {
DateTimeFormatter base = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
DateTimeFormatter test = base.withLocale(Locale.GERMAN);
assertEquals(test.getLocale(), Locale.GERMAN);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_parse_CharSequence_ParsePosition.
//-----------------------------------------------------------------------
// parse(CharSequence)
//-----------------------------------------------------------------------
@Test
public void test_parse_CharSequence_ParsePosition() {
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
ParsePosition pos = new ParsePosition(3);
TemporalAccessor result = test.parse("XXXONE30XXX", pos);
assertEquals(pos.getIndex(), 8);
assertEquals(pos.getErrorIndex(), -1);
assertEquals(result.isSupported(DAY_OF_MONTH), true);
assertEquals(result.getLong(DAY_OF_MONTH), 30L);
assertEquals(result.isSupported(HOUR_OF_DAY), false);
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_parseUnresolved_StringParsePosition_duplicateFieldSameValue.
@Test
public void test_parseUnresolved_StringParsePosition_duplicateFieldSameValue() {
DateTimeFormatter test = new DateTimeFormatterBuilder().appendValue(MONTH_OF_YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).toFormatter();
ParsePosition pos = new ParsePosition(3);
TemporalAccessor result = test.parseUnresolved("XXX6-6", pos);
assertEquals(pos.getIndex(), 6);
assertEquals(pos.getErrorIndex(), -1);
assertEquals(result.getLong(MONTH_OF_YEAR), 6);
}
use of java.time.format.DateTimeFormatter 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.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_parse_CharSequence_ParsePosition_nullText.
@Test(expectedExceptions = NullPointerException.class)
public void test_parse_CharSequence_ParsePosition_nullText() {
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
test.parse((CharSequence) null, new ParsePosition(0));
}
Aggregations