use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKDateTimeFormatter method test_toFormat_format_notTemporal.
@Test(expectedExceptions = IllegalArgumentException.class)
public void test_toFormat_format_notTemporal() throws Exception {
DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
Format format = test.toFormat();
format.format("Not a Temporal");
}
use of java.time.format.DateTimeFormatter 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.DateTimeFormatter 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);
}
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoyDow.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(woyField).appendLiteral(':').appendValue(dowField).toFormatter();
String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(woyField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
use of java.time.format.DateTimeFormatter in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWomDow_lenient.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWomDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
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(dowField).toFormatter().withResolverStyle(LENIENT);
int wom = date.get(womField);
int dow = date.get(dowField);
for (int j = wom - 10; j < wom + 10; j++) {
String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
Aggregations