本文整理匯總了Java中java.time.LocalDate.range方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.range方法的具體用法?Java LocalDate.range怎麽用?Java LocalDate.range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.range方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_rangeWeekOfWeekBasedYear
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_rangeWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields weekFields = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekFields.dayOfWeek();
TemporalField wowByField = weekFields.weekOfWeekBasedYear();
LocalDate day1 = LocalDate.of(2012, 1, weekFields.getMinimalDaysInFirstWeek());
day1 = day1.with(wowByField, 1).with(dowField, 1);
LocalDate day2 = LocalDate.of(2013, 1, weekFields.getMinimalDaysInFirstWeek());
day2 = day2.with(wowByField, 1).with(dowField, 1);
int expectedWeeks = (int)ChronoUnit.DAYS.between(day1, day2) / 7;
ValueRange range = day1.range(wowByField);
assertEquals(range.getMaximum(), expectedWeeks, "Range incorrect");
}
示例2: test_fieldRanges
import java.time.LocalDate; //導入方法依賴的package包/類
@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);
}
}
示例3: test_withWeekOfWeekBasedYear
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
int dowExpected = (day.get(dowField) - 1) % 7 + 1;
LocalDate dowDate = day.with(dowField, dowExpected);
int dowResult = dowDate.get(dowField);
assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
int weekExpected = day.get(wowbyField) + 1;
ValueRange range = day.range(wowbyField);
weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
LocalDate weekDate = day.with(wowbyField, weekExpected);
int weekResult = weekDate.get(wowbyField);
assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
int yearExpected = day.get(yowbyField) + 1;
LocalDate yearDate = day.with(yowbyField, yearExpected);
int yearResult = yearDate.get(yowbyField);
assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
range = yearDate.range(wowbyField);
weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());
int weekActual = yearDate.get(wowbyField);
assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}