本文整理匯總了Java中org.joda.time.MutableDateTime.isBefore方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime.isBefore方法的具體用法?Java MutableDateTime.isBefore怎麽用?Java MutableDateTime.isBefore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.MutableDateTime
的用法示例。
在下文中一共展示了MutableDateTime.isBefore方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTimeBefore
import org.joda.time.MutableDateTime; //導入方法依賴的package包/類
public DateTime getTimeBefore(DateTime dateTime) {
try {
String[] fixedCronExp = appendYearField(expression.split("\\s+"));
validate(fixedCronExp);
MutableDateTime mdt = dateTime.toMutableDateTime();
mdt.setMillisOfSecond(0);
List<Integer> secondValues = parse(secondParsers, fixedCronExp[AbstractParser.DurationField.SECOND.getIndex()], dateTime, AbstractParser.DurationField.SECOND);
List<Integer> minuteValues = parse(minuteParsers, fixedCronExp[AbstractParser.DurationField.MINUTE.getIndex()], dateTime, AbstractParser.DurationField.MINUTE);
List<Integer> hourValues = parse(hourParsers, fixedCronExp[AbstractParser.DurationField.HOUR.getIndex()], dateTime, AbstractParser.DurationField.HOUR);
List<Integer> monthValues = parse(monthParsers, fixedCronExp[AbstractParser.DurationField.MONTH.getIndex()], dateTime, AbstractParser.DurationField.MONTH);
List<Integer> yearValues = parse(yearParsers, fixedCronExp[AbstractParser.DurationField.YEAR.getIndex()], dateTime, AbstractParser.DurationField.YEAR);
int yearStartIndex = searchNotGreaterThanIndex(yearValues, mdt.getYear());
for (int yearIndex = yearStartIndex; yearIndex >= 0; yearIndex--) {
int year = yearValues.get(yearIndex);
mdt.setYear(year);
int monthStartIndex = (year == dateTime.getYear()) ? searchNotGreaterThanIndex(monthValues, dateTime.getMonthOfYear())
: monthValues.size() - 1;
for (int monthIndex = monthStartIndex; monthIndex >= 0; monthIndex--) {
int month = monthValues.get(monthIndex);
mdt.setMonthOfYear(month);
List<Integer> dayValues = parseDayValueList(fixedCronExp, mdt.toDateTime());
int dayStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear())
? searchNotGreaterThanIndex(dayValues, dateTime.getDayOfMonth()) : dayValues.size() - 1;
int maxDayOfMonth = mdt.toDateTime().dayOfMonth().withMaximumValue().toLocalDate().getDayOfMonth();
for (int dayIndex = dayStartIndex; dayIndex >= 0; dayIndex--) {
int day = dayValues.get(dayIndex);
if (day > maxDayOfMonth) {
break;
}
mdt.setDayOfMonth(day);
int hourStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear() && day == dateTime.getDayOfMonth())
? searchNotGreaterThanIndex(hourValues, dateTime.getHourOfDay()) : hourValues.size() - 1;
for (int hourIndex = hourStartIndex; hourIndex >= 0; hourIndex--) {
int hour = hourValues.get(hourIndex);
mdt.setHourOfDay(hour);
int minuteStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay())
? searchNotGreaterThanIndex(minuteValues, dateTime.getMinuteOfHour()) : minuteValues.size() - 1;
for (int minuteIndex = minuteStartIndex; minuteIndex >= 0; minuteIndex--) {
int minute = minuteValues.get(minuteIndex);
mdt.setMinuteOfHour(minute);
int secondStartIndex = (year == dateTime.getYear() && month == dateTime.getMonthOfYear()
&& day == dateTime.getDayOfMonth() && hour == dateTime.getHourOfDay() && minute == dateTime.getMinuteOfHour())
? searchNotGreaterThanIndex(secondValues, dateTime.getSecondOfMinute()) : secondValues.size() - 1;
for (int secondIndex = secondStartIndex; secondIndex >= 0; secondIndex--) {
int second = secondValues.get(secondIndex);
mdt.setSecondOfMinute(second);
if (mdt.isBefore(dateTime)) {
return mdt.toDateTime();
}
}
}
}
}
}
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
return null;
}