下面列出了org.joda.time.LocalDate#withDayOfWeek ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static CalendarWeek getWeekIncludeThisDay(LocalDate localDate) {
LocalDate monday = localDate.withDayOfWeek(DateTimeConstants.MONDAY);
LocalDate tuesday = localDate.withDayOfWeek(DateTimeConstants.TUESDAY);
LocalDate wednesday = localDate.withDayOfWeek(DateTimeConstants.WEDNESDAY);
LocalDate thursday = localDate.withDayOfWeek(DateTimeConstants.THURSDAY);
LocalDate friday = localDate.withDayOfWeek(DateTimeConstants.FRIDAY);
LocalDate saturday = localDate.withDayOfWeek(DateTimeConstants.SATURDAY);
LocalDate sunday = localDate.withDayOfWeek(DateTimeConstants.SUNDAY);
CalendarWeek calendarWeek = new CalendarWeek(
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
);
calendarWeek.firstDayOfCurrentMonth = localDate.withDayOfMonth(1);
calendarWeek.originDate = localDate;
return calendarWeek;
}
public static Collection<DateRange> splitAsDateRangeByWeek(LocalDate start, LocalDate end){
Set<DateRange> dates = new LinkedHashSet<DateRange>();
dates.add(new DateRange(start, start.withDayOfWeek(DateTimeConstants.SUNDAY)));
LocalDate startDateOfWeek = start.withDayOfWeek(DateTimeConstants.MONDAY).plusWeeks(1);
while(!startDateOfWeek.isAfter(end)){
LocalDate endDateOfWeek = startDateOfWeek.withDayOfWeek(DateTimeConstants.SUNDAY);
if(endDateOfWeek.isAfter(end)){
endDateOfWeek = end;
}
dates.add(new DateRange(startDateOfWeek, endDateOfWeek));
startDateOfWeek = startDateOfWeek.plusWeeks(1);
}
return dates;
}
@Override
protected LocalDate getMaxDateCanEdit() {
LocalDate periodDate = LocalDate.parse(period, DateTimeFormat.forPattern(getDateFormat()));
periodDate = periodDate.withDayOfWeek(weekStarts());
periodDate = periodDate.plusDays(6);
return periodDate.plusDays(expiryDays - 1);
}
/**
* Assumes that the month is correct, get the day for the 2rd wednesday.
*
* @param original
* the start date
* @return the 3rd Wednesday of the month
*/
private LocalDate calculate3rdWednesday(final LocalDate original) {
final LocalDate firstOfMonth = original.withDayOfMonth(1);
LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER);
if (firstWed.isBefore(firstOfMonth)) {
firstWed = firstWed.plusWeeks(1);
}
return firstWed.plusWeeks(2);
}