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

The following examples show how to use org.joda.time.MutableDateTime#setDayOfMonth() . 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: MYearWeek.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int dayOfYear = cal.getDayOfYear();

    if (dayOfYear < firstD) return modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
    else return yr * 100 + (dayOfYear - firstD) / 7 +1;
}
 
Example 2
Source File: MWeek.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
private static int getMode0257(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);
    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr); 
    cal.setMonthOfYear(mo); 
    cal.setDayOfMonth(da); 

    int dayOfYear = cal.getDayOfYear(); 

    if (dayOfYear < firstD) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
    else return (dayOfYear - firstD) / 7 +1;
}
 
Example 3
Source File: XMLGregorianCalendarToDateTimeConverter.java    From components with Apache License 2.0 6 votes vote down vote up
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
 
Example 4
Source File: MYearWeek.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay)
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
    if (firstD < 4)
    {
        if (week < 0) return  modes[lowestVal].getYearWeek(cal, yr - 1, 12, 31);
        else return yr * 100 + week / 7 + 1;
    }
    else
    {
        if (week < 0) return yr * 100 + 1;
        else return yr * 100 + week / 7 + 2;
    }
}
 
Example 5
Source File: MWeek.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
private static int getMode1346(MutableDateTime cal, int yr, int mo, int da, int firstDay, int lowestVal)
{
    cal.setYear(yr);
    cal.setMonthOfYear(1);
    cal.setDayOfMonth(1);

    int firstD = 1;

    while (cal.getDayOfWeek() != firstDay) 
        cal.setDayOfMonth(++firstD);

    cal.setYear(yr);
    cal.setMonthOfYear(mo);
    cal.setDayOfMonth(da);

    int week = cal.getDayOfYear() - (firstD +1 ); // Sun/Mon
    if (firstD < 4)
    {
        if (week < 0) return modes[lowestVal].getWeek(cal, yr-1, 12, 31);
        else return week / 7 + 1;
    }
    else
    {
        if (week < 0) return 1;
        else return week / 7 + 2;
    }
}
 
Example 6
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 7
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 8
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();
}