本文整理汇总了Java中org.threeten.bp.Month.JANUARY属性的典型用法代码示例。如果您正苦于以下问题:Java Month.JANUARY属性的具体用法?Java Month.JANUARY怎么用?Java Month.JANUARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.threeten.bp.Month
的用法示例。
在下文中一共展示了Month.JANUARY属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchedule
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) {
ArgumentChecker.notNull(startDate, "start date");
ArgumentChecker.notNull(endDate, "end date");
ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date");
if (startDate.equals(endDate)) {
if (startDate.getDayOfMonth() == 1 && startDate.getMonth() == Month.JANUARY) {
return new LocalDate[] {startDate};
}
throw new IllegalArgumentException("Start date and end date were the same but neither was the first day of the year");
}
final List<LocalDate> dates = new ArrayList<>();
LocalDate date = startDate.with(TemporalAdjusters.firstDayOfYear());
if (date.isBefore(startDate)) {
date = date.plusYears(1);
}
while (!date.isAfter(endDate)) {
dates.add(date);
date = date.plusYears(1);
}
return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}
示例2: getSchedule
public LocalDate[] getSchedule(final LocalDate startDate, final LocalDate endDate) {
ArgumentChecker.notNull(startDate, "start date");
ArgumentChecker.notNull(endDate, "end date");
ArgumentChecker.isFalse(startDate.isAfter(endDate), "start date must not be after end date");
if (startDate.equals(endDate)) {
if (startDate.getDayOfMonth() == _dayOfMonth) {
return new LocalDate[] {startDate};
}
throw new IllegalArgumentException("Start date and end date were the same but their day of month was not the same as that required");
}
final List<LocalDate> dates = new ArrayList<>();
int year = endDate.getYear();
Month month = startDate.getMonth();
LocalDate date = startDate.withMonth(month.getValue()).withDayOfMonth(_dayOfMonth);
if (date.isBefore(startDate)) {
month = month.plus(1);
date = date.withMonth(month.getValue());
}
year = date.getYear();
while (!date.isAfter(endDate)) {
dates.add(date);
month = month.plus(1);
if (month == Month.JANUARY) {
year++;
}
date = LocalDate.of(year, month.getValue(), _dayOfMonth);
}
return dates.toArray(EMPTY_LOCAL_DATE_ARRAY);
}