Java Code Examples for org.joda.time.MutableDateTime#addMonths()

The following examples show how to use org.joda.time.MutableDateTime#addMonths() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CronExpression.java    From chronos with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@CoverageIgnore
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);
    nextTime.secondOfDay().add(1);

    while (true) { // day of week
        while (true) { // month
            while (true) { // day of month
                while (true) { // hour
                    while (true) { // minute
                        while (true) { // second
                            if (secondField.matches(nextTime.getSecondOfMinute())) {
                                break;
                            }
                            nextTime.secondOfDay().add(1);
                        }
                        if (minuteField.matches(nextTime.getMinuteOfHour())) {
                            break;
                        }
                        nextTime.minuteOfDay().add(1);
                        nextTime.secondOfMinute().set(0);
                    }
                    if (hourField.matches(nextTime.getHourOfDay())) {
                        break;
                    }
                    nextTime.hourOfDay().add(1);
                    nextTime.minuteOfHour().set(0);
                    nextTime.secondOfMinute().set(0);
                }
                if (dayOfMonthField.matches(new LocalDate(nextTime))) {
                    break;
                }
                nextTime.addDays(1);
                nextTime.setTime(0, 0, 0, 0);
                checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
            }
            if (monthField.matches(nextTime.getMonthOfYear())) {
                break;
            }
            nextTime.addMonths(1);
            nextTime.setDayOfMonth(1);
            nextTime.setTime(0, 0, 0, 0);
            checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
        }
        if (dayOfWeekField.matches(new LocalDate(nextTime))) {
            break;
        }
        nextTime.addDays(1);
        nextTime.setTime(0, 0, 0, 0);
        checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
    }

    return nextTime.toDateTime();
}
 
Example 2
Source File: MDateAddSub.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void compute(MutableDateTime date, long delta)
{
    date.addMonths((int)delta);
}
 
Example 3
Source File: MDateAddSub.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void compute(MutableDateTime date, long delta)
{
    date.addMonths(-(int)delta);
}
 
Example 4
Source File: CronExpression.java    From cron with Apache License 2.0 4 votes vote down vote up
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);
    nextTime.secondOfDay().add(1);

    while (true) { // day of week
        while (true) { // month
            while (true) { // day of month
                while (true) { // hour
                    while (true) { // minute
                        while (true) { // second
                            if (secondField.matches(nextTime.getSecondOfMinute())) {
                                break;
                            }
                            nextTime.secondOfDay().add(1);
                        }
                        if (minuteField.matches(nextTime.getMinuteOfHour())) {
                            break;
                        }
                        nextTime.minuteOfDay().add(1);
                        nextTime.secondOfMinute().set(0);
                    }
                    if (hourField.matches(nextTime.getHourOfDay())) {
                        break;
                    }
                    nextTime.hourOfDay().add(1);
                    nextTime.minuteOfHour().set(0);
                    nextTime.secondOfMinute().set(0);
                }
                if (dayOfMonthField.matches(new LocalDate(nextTime))) {
                    break;
                }
                nextTime.addDays(1);
                nextTime.setTime(0, 0, 0, 0);
                checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
            }
            if (monthField.matches(nextTime.getMonthOfYear())) {
                break;
            }
            nextTime.addMonths(1);
            nextTime.setDayOfMonth(1);
            nextTime.setTime(0, 0, 0, 0);
            checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
        }
        if (dayOfWeekField.matches(new LocalDate(nextTime))) {
            break;
        }
        nextTime.addDays(1);
        nextTime.setTime(0, 0, 0, 0);
        checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
    }

    return nextTime.toDateTime();
}
 
Example 5
Source File: CronExpression.java    From actframework with Apache License 2.0 4 votes vote down vote up
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);
    nextTime.secondOfDay().add(1);

    while (true) { // day of week
        while (true) { // month
            while (true) { // day of month
                while (true) { // hour
                    while (true) { // minute
                        while (true) { // second
                            if (secondField.matches(nextTime.getSecondOfMinute())) {
                                break;
                            }
                            nextTime.secondOfDay().add(1);
                        }
                        if (minuteField.matches(nextTime.getMinuteOfHour())) {
                            break;
                        }
                        nextTime.minuteOfDay().add(1);
                        nextTime.secondOfMinute().set(0);
                    }
                    if (hourField.matches(nextTime.getHourOfDay())) {
                        break;
                    }
                    nextTime.hourOfDay().add(1);
                    nextTime.minuteOfHour().set(0);
                    nextTime.secondOfMinute().set(0);
                }
                if (dayOfMonthField.matches(new LocalDate(nextTime))) {
                    break;
                }
                nextTime.addDays(1);
                nextTime.setTime(0, 0, 0, 0);
                checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
            }
            if (monthField.matches(nextTime.getMonthOfYear())) {
                break;
            }
            nextTime.addMonths(1);
            nextTime.setDayOfMonth(1);
            nextTime.setTime(0, 0, 0, 0);
            checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
        }
        if (dayOfWeekField.matches(new LocalDate(nextTime))) {
            break;
        }
        nextTime.addDays(1);
        nextTime.setTime(0, 0, 0, 0);
        checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier);
    }

    return nextTime.toDateTime();
}