use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoyDow_lenient.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoyDow_lenient(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(woyField).appendLiteral(':').appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(dowField);
for (int j = woy - 60; j < woy + 60; j++) {
String str = date.getYear() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWom_strict.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWom_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = week.weekOfMonth();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:1:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.getYear(), 2012);
assertEquals(date.getMonthValue(), 1);
assertEquals(date.get(womField), 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_localizedWoWBYDow_lenient.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(yowbyField).appendLiteral(':').appendValue(wowbyField).appendLiteral(':').appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int wowby = date.get(wowbyField);
int dow = date.get(dowField);
for (int j = wowby - 60; j < wowby + 60; j++) {
String str = date.get(yowbyField) + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_weeks_LENIENT.
@Test(dataProvider = "week")
public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) {
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(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
use of java.time.format.DateTimeFormatterBuilder in project jdk8u_jdk by JetBrains.
the class TCKIsoFields method test_parse_weeks_SMART.
@Test(dataProvider = "week")
public void test_parse_weeks_SMART(LocalDate date, DayOfWeek dow, int week, int wby) {
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);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
Aggregations