下面列出了org.joda.time.YearMonthDay#plusDays ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ViewEventSpaceOccupationsBean(YearMonthDay day, Space allocatableSpace) {
setAllocatableSpace(allocatableSpace);
if (day != null) {
setYear(new Partial(DateTimeFieldType.year(), day.getYear()));
setMonth(new Partial(DateTimeFieldType.monthOfYear(), day.getMonthOfYear()));
YearMonthDay monday = day.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();
if ((monday.getMonthOfYear() < day.getMonthOfYear()) || (monday.getYear() < day.getYear())) {
monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
}
setDay(monday);
}
}
@Override
public Object provide(Object source, Object currentValue) {
List<YearMonthDay> result = new ArrayList<YearMonthDay>();
ViewEventSpaceOccupationsBean bean = (ViewEventSpaceOccupationsBean) source;
Partial year = bean.getYear();
Partial month = bean.getMonth();
if (month != null && year != null) {
int monthNumber = month.get(DateTimeFieldType.monthOfYear());
int yearNumber = year.get(DateTimeFieldType.year());
YearMonthDay firstDayOfMonth = new YearMonthDay(yearNumber, monthNumber, 1);
YearMonthDay monday = firstDayOfMonth.toDateTimeAtMidnight().withDayOfWeek(MONDAY_IN_JODA_TIME).toYearMonthDay();
if ((monday.getMonthOfYear() < monthNumber) || (monday.getYear() < yearNumber)) {
monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
}
while (monday.getMonthOfYear() == monthNumber) {
result.add(monday);
monday = monday.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
}
}
return result;
}
private YearMonthDay getValidBeginDate(YearMonthDay startDate) {
YearMonthDay lessonBegin =
startDate.toDateTimeAtMidnight().withDayOfWeek(getDiaSemana().getDiaSemanaInDayOfWeekJodaFormat())
.toYearMonthDay();
if (lessonBegin.isBefore(startDate)) {
lessonBegin = lessonBegin.plusDays(NUMBER_OF_DAYS_IN_WEEK);
}
return lessonBegin;
}
private SortedSet<YearMonthDay> getAllValidLessonDatesWithoutInstancesDates(YearMonthDay startDateToSearch,
YearMonthDay endDateToSearch) {
SortedSet<YearMonthDay> result = new TreeSet<YearMonthDay>();
startDateToSearch = startDateToSearch != null ? getValidBeginDate(startDateToSearch) : null;
if (!wasFinished() && startDateToSearch != null && endDateToSearch != null && !startDateToSearch.isAfter(endDateToSearch)) {
Space lessonCampus = getLessonCampus();
final int dayIncrement =
getFrequency() == FrequencyType.BIWEEKLY ? FrequencyType.WEEKLY.getNumberOfDays() : getFrequency()
.getNumberOfDays();
boolean shouldAdd = true;
while (true) {
if (isDayValid(startDateToSearch, lessonCampus)) {
if (getFrequency() != FrequencyType.BIWEEKLY || shouldAdd) {
if (!isHoliday(startDateToSearch, lessonCampus)) {
result.add(startDateToSearch);
}
}
shouldAdd = !shouldAdd;
}
startDateToSearch = startDateToSearch.plusDays(dayIncrement);
if (startDateToSearch.isAfter(endDateToSearch)) {
break;
}
}
}
return result;
}
public static List<Interval> generateEventSpaceOccupationIntervals(YearMonthDay begin, final YearMonthDay end,
final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday,
final YearMonthDay startDateToSearch, final YearMonthDay endDateToSearch) {
List<Interval> result = new ArrayList<Interval>();
begin = getBeginDateInSpecificWeekDay(diaSemana, begin);
if (frequency == null) {
if (!begin.isAfter(end)
&& (startDateToSearch == null || (!end.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch)))) {
result.add(createNewInterval(begin, end, beginTime, endTime));
return result;
}
} else {
int numberOfDaysToSum = frequency.getNumberOfDays();
while (true) {
if (begin.isAfter(end)) {
break;
}
if (startDateToSearch == null || (!begin.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch))) {
Interval interval = createNewInterval(begin, begin, beginTime, endTime);
if (!frequency.equals(FrequencyType.DAILY)
|| ((dailyFrequencyMarkSaturday || interval.getStart().getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || interval
.getStart().getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {
result.add(interval);
}
}
begin = begin.plusDays(numberOfDaysToSum);
}
}
return result;
}
protected DateTime getInstant(boolean firstInstant, YearMonthDay begin, final YearMonthDay end,
final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday, final Boolean dailyFrequencyMarkSunday) {
DateTime instantResult = null;
begin = getBeginDateInSpecificWeekDay(diaSemana, begin);
if (frequency == null) {
if (!begin.isAfter(end)) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
}
}
} else {
int numberOfDaysToSum = frequency.getNumberOfDays();
while (true) {
if (begin.isAfter(end)) {
break;
}
DateTime intervalEnd = begin.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
if (!frequency.equals(FrequencyType.DAILY)
|| ((dailyFrequencyMarkSaturday || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (dailyFrequencyMarkSunday || intervalEnd
.getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {
if (firstInstant) {
return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
} else {
instantResult = intervalEnd;
}
}
begin = begin.plusDays(numberOfDaysToSum);
}
}
return instantResult;
}
private static YearMonthDay getBeginDateInSpecificWeekDay(DiaSemana diaSemana, YearMonthDay begin) {
if (diaSemana != null) {
YearMonthDay newBegin =
begin.toDateTimeAtMidnight().withDayOfWeek(diaSemana.getDiaSemanaInDayOfWeekJodaFormat()).toYearMonthDay();
if (newBegin.isBefore(begin)) {
begin = newBegin.plusDays(Lesson.NUMBER_OF_DAYS_IN_WEEK);
} else {
begin = newBegin;
}
}
return begin;
}
private YearMonthDay findNextPossibleDateAfter(YearMonthDay day, Lesson lesson) {
for (YearMonthDay lessonDay : lesson.getAllLessonDatesWithoutInstanceDates()) {
if (lessonDay.isAfter(day)) {
return lessonDay;
}
}
return lesson.isBiWeeklyOffset() ? day.plusDays(8) : day.plusDays(1);
}