本文整理汇总了Java中java.time.temporal.WeekFields.getMinimalDaysInFirstWeek方法的典型用法代码示例。如果您正苦于以下问题:Java WeekFields.getMinimalDaysInFirstWeek方法的具体用法?Java WeekFields.getMinimalDaysInFirstWeek怎么用?Java WeekFields.getMinimalDaysInFirstWeek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.temporal.WeekFields
的用法示例。
在下文中一共展示了WeekFields.getMinimalDaysInFirstWeek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_weekOfWeekBasedYearField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
* Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
* and WeekBasedYear for every combination of start of week
* and minimal days in week.
* @param firstDayOfWeek the first day of the week
* @param minDays the minimum number of days in the week
*/
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekDef.dayOfWeek();
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
TemporalField yowbyField = weekDef.weekBasedYear();
for (int i = 1; i <= 15; i++) {
int actualDOW = day.get(dowField);
int actualWOWBY = day.get(wowbyField);
int actualYOWBY = day.get(yowbyField);
// Verify that the combination of day of week and week of month can be used
// to reconstruct the same date.
LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
DayOfWeek isoDOW = day1.getDayOfWeek();
int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;
int weekStart = Math.floorMod(1 - dow, 7);
if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
// The previous week has the minimum days in the current month to be a 'week'
weekStart -= 7;
}
weekStart += actualDOW - 1;
weekStart += (actualWOWBY - 1) * 7;
LocalDate result = day1.plusDays(weekStart);
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
+ String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
day = day.plusDays(1);
}
}