use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKLocalizedFieldPrinter method test_print_WeekBasedYear.
@Test(dataProvider = "LocalWeekBasedYearPatterns")
public void test_print_WeekBasedYear(String pattern, String expectedText, LocalDate date) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern, locale);
String result = dtf.format(date);
WeekFields weekDef = WeekFields.of(locale);
assertEquals(result, expectedText, "Incorrect formatting for " + pattern + ", weekDef: " + weekDef);
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoy_lenient.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoy_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(woyField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(DAY_OF_WEEK);
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.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWomDow.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWomDow(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 <= 15; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(dowField).toFormatter();
String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(womField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoWBY.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoWBY(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
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(DAY_OF_WEEK).toFormatter();
String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_equals.
//-----------------------------------------------------------------------
// equals() and hashCode().
//-----------------------------------------------------------------------
@Test
public void test_equals() {
WeekFields weekDef_iso = WeekFields.ISO;
WeekFields weekDef_sundayStart = WeekFields.SUNDAY_START;
assertTrue(weekDef_iso.equals(WeekFields.of(DayOfWeek.MONDAY, 4)));
assertTrue(weekDef_sundayStart.equals(WeekFields.of(DayOfWeek.SUNDAY, 1)));
assertEquals(weekDef_iso.hashCode(), WeekFields.of(DayOfWeek.MONDAY, 4).hashCode());
assertEquals(weekDef_sundayStart.hashCode(), WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode());
assertFalse(weekDef_iso.equals(weekDef_sundayStart));
assertNotEquals(weekDef_iso.hashCode(), weekDef_sundayStart.hashCode());
}
Aggregations