use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_basics.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_basics(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
assertEquals(week.dayOfWeek().isDateBased(), true);
assertEquals(week.dayOfWeek().isTimeBased(), false);
assertEquals(week.weekOfMonth().isDateBased(), true);
assertEquals(week.weekOfMonth().isTimeBased(), false);
assertEquals(week.weekOfYear().isDateBased(), true);
assertEquals(week.weekOfYear().isTimeBased(), false);
assertEquals(week.weekOfWeekBasedYear().isDateBased(), true);
assertEquals(week.weekOfWeekBasedYear().isTimeBased(), false);
assertEquals(week.weekBasedYear().isDateBased(), true);
assertEquals(week.weekBasedYear().isTimeBased(), false);
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_fieldRanges.
@Test(dataProvider = "weekFields")
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = weekDef.weekOfMonth();
TemporalField woyField = weekDef.weekOfYear();
LocalDate day = LocalDate.of(2012, 11, 30);
LocalDate endDay = LocalDate.of(2013, 1, 2);
while (day.isBefore(endDay)) {
LocalDate last = day.with(DAY_OF_MONTH, day.lengthOfMonth());
int lastWOM = last.get(womField);
LocalDate first = day.with(DAY_OF_MONTH, 1);
int firstWOM = first.get(womField);
ValueRange rangeWOM = day.range(womField);
assertEquals(rangeWOM.getMinimum(), firstWOM, "Range min should be same as WeekOfMonth for first day of month: " + first + ", " + weekDef);
assertEquals(rangeWOM.getMaximum(), lastWOM, "Range max should be same as WeekOfMonth for last day of month: " + last + ", " + weekDef);
last = day.with(DAY_OF_YEAR, day.lengthOfYear());
int lastWOY = last.get(woyField);
first = day.with(DAY_OF_YEAR, 1);
int firstWOY = first.get(woyField);
ValueRange rangeWOY = day.range(woyField);
assertEquals(rangeWOY.getMinimum(), firstWOY, "Range min should be same as WeekOfYear for first day of Year: " + day + ", " + weekDef);
assertEquals(rangeWOY.getMaximum(), lastWOY, "Range max should be same as WeekOfYear for last day of Year: " + day + ", " + weekDef);
day = day.plusDays(1);
}
}
use of java.time.temporal.WeekFields 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);
}
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_WOWBY.
//-----------------------------------------------------------------------
// WEEK_OF_WEEK_BASED_YEAR
// Validate with the same data used by IsoFields.
//-----------------------------------------------------------------------
@Test(dataProvider = "IsoWeekData")
public void test_WOWBY(LocalDate date, DayOfWeek dow, int week, int wby) {
WeekFields weekDef = WeekFields.ISO;
TemporalField dowField = weekDef.dayOfWeek();
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
TemporalField yowbyField = weekDef.weekBasedYear();
assertEquals(date.get(dowField), dow.getValue());
assertEquals(date.get(wowbyField), week);
assertEquals(date.get(yowbyField), wby);
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_of_DayOfWeek_int_singleton.
@Test(dataProvider = "weekFields")
public void test_of_DayOfWeek_int_singleton(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
assertEquals(week.getFirstDayOfWeek(), firstDayOfWeek, "Incorrect firstDayOfWeek");
assertEquals(week.getMinimalDaysInFirstWeek(), minDays, "Incorrect MinimalDaysInFirstWeek");
assertSame(WeekFields.of(firstDayOfWeek, minDays), week);
}
Aggregations