Example usage for org.joda.time MutableDateTime getSecondOfMinute

List of usage examples for org.joda.time MutableDateTime getSecondOfMinute

Introduction

In this page you can find the example usage for org.joda.time MutableDateTime getSecondOfMinute.

Prototype

public int getSecondOfMinute() 

Source Link

Document

Get the second of minute field value.

Usage

From source file:br.com.centralit.evm.citsmartevm.util.CronExpression.java

License:Apache License

public DateTime nextTimeAfter(DateTime afterTime) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);/*from  w w  w  .j ava 2  s  .  c  o  m*/
    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);
            }
            if (monthField.matches(nextTime.getMonthOfYear())) {
                break;
            }
            nextTime.addMonths(1);
            nextTime.setDayOfMonth(1);
            nextTime.setTime(0, 0, 0, 0);
        }
        if (dayOfWeekField.matches(new LocalDate(nextTime))) {
            break;
        }
        nextTime.addDays(1);
        nextTime.setTime(0, 0, 0, 0);
    }

    return nextTime.toDateTime();
}

From source file:com.huffingtonpost.chronos.util.CronExpression.java

License:Apache License

@CoverageIgnore
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);//from ww w .  j av  a2  s  .c  o  m
    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();
}

From source file:fc.cron.CronExpression.java

License:Apache License

public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) {
    MutableDateTime nextTime = new MutableDateTime(afterTime);
    nextTime.setMillisOfSecond(0);/*from  w ww  .jav a2  s.  co m*/
    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();
}

From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java

License:Open Source License

@Override
public XMLGregorianCalendar convertToDatum(Object timestamp) {
    if (timestamp == null) {
        return null;
    }// w  w w. j av a  2s.co m

    long timestampMillis;
    if (timestamp instanceof Long) {
        timestampMillis = ((Long) timestamp).longValue();
    } else if (timestamp instanceof Date) {
        timestampMillis = ((Date) timestamp).getTime();
    } else {
        throw new IllegalArgumentException("Unsupported Avro timestamp value: " + timestamp);
    }

    MutableDateTime dateTime = new MutableDateTime();
    dateTime.setMillis(timestampMillis);

    XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
    xts.setYear(dateTime.getYear());
    xts.setMonth(dateTime.getMonthOfYear());
    xts.setDay(dateTime.getDayOfMonth());
    xts.setHour(dateTime.getHourOfDay());
    xts.setMinute(dateTime.getMinuteOfHour());
    xts.setSecond(dateTime.getSecondOfMinute());
    xts.setMillisecond(dateTime.getMillisOfSecond());
    xts.setTimezone(dateTime.getZone().toTimeZone().getOffset(dateTime.getMillis()) / 60000);

    return xts;
}

From source file:org.wso2.analytics.esb.util.TimeRangeUtils.java

License:Open Source License

public static List<TimeRange> getDateTimeRanges(long from, long to) {
    List<TimeRange> ranges = new ArrayList<>(10);
    MutableDateTime fromDate = new MutableDateTime(from);
    fromDate.set(DateTimeFieldType.millisOfSecond(), 0);
    MutableDateTime toDate = new MutableDateTime(to);
    toDate.set(DateTimeFieldType.millisOfSecond(), 0);
    MutableDateTime tempFromTime = fromDate.copy();
    MutableDateTime tempToTime = toDate.copy();

    if (log.isDebugEnabled()) {
        log.debug("Time range: " + formatter.format(fromDate.toDate()) + " -> "
                + formatter.format(toDate.toDate()));
    }//  ww  w .  j  a va2  s.co m

    if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) {
        ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                new long[] { fromDate.getMillis(), toDate.getMillis() }));
    } else {
        if (tempFromTime.getSecondOfMinute() != 0
                && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) {
            tempFromTime = tempFromTime.minuteOfHour().roundCeiling();
            ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getMinuteOfHour() != 0
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) {
            fromDate = tempFromTime.copy();
            if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) {
                tempFromTime = tempFromTime.minuteOfHour().add(
                        (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE);
            } else {
                tempFromTime = tempFromTime.hourOfDay().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.MINUTE.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getHourOfDay() != 0
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) {
            fromDate = tempFromTime.copy();
            if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) {
                tempFromTime = tempFromTime.hourOfDay().add(
                        (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR);
            } else {
                tempFromTime = tempFromTime.dayOfMonth().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.HOUR.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getDayOfMonth() != 1
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) {
            fromDate = tempFromTime.copy();
            if ((((toDate.getMillis() - tempFromTime.getMillis())
                    / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) {
                tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis())
                        / ((long) DateTimeConstants.MILLIS_PER_DAY)));
            } else {
                tempFromTime = tempFromTime.monthOfYear().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.DAY.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempToTime.getSecondOfMinute() != 0
                && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) {
            toDate = tempToTime.copy();
            long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND;
            if (remainingSeconds < 60) {
                tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds);

            } else {
                tempToTime = tempToTime.secondOfMinute().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis()
                - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) {
            toDate = tempToTime.copy();
            long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE;
            if (remainingMinutes < 60) {
                tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes);
            } else {
                tempToTime = tempToTime.hourOfDay().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.MINUTE.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getHourOfDay() != 0
                && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) {
            toDate = tempToTime.copy();
            long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR;
            if (remainingHours < 24) {
                tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours);
            } else {
                tempToTime = tempToTime.dayOfMonth().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.HOUR.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getDayOfMonth() != 1
                && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) {
            toDate = tempToTime.copy();
            tempToTime = tempToTime.monthOfYear().roundFloor();
            ranges.add(new TimeRange(RangeUnit.DAY.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.isAfter(tempFromTime)) {
            ranges.add(new TimeRange(RangeUnit.MONTH.name(),
                    new long[] { tempFromTime.getMillis(), tempToTime.getMillis() }));
        }
    }
    if (log.isDebugEnabled()) {
        for (TimeRange timeRange : ranges) {
            log.debug("Unit: " + timeRange.getUnit() + " Range: "
                    + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0]
                    + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "("
                    + timeRange.getRange()[1] + ")");
        }
    }
    return ranges;
}

From source file:org.wso2.analytics.shared.util.time.TimeRangeUtils.java

License:Open Source License

public static List<TimeRange> getDateTimeRanges(long from, long to) {
    List<TimeRange> ranges = new ArrayList<>(10);
    MutableDateTime fromDate = new MutableDateTime(from);
    fromDate.set(DateTimeFieldType.millisOfSecond(), 0);
    MutableDateTime toDate = new MutableDateTime(to);
    toDate.set(DateTimeFieldType.millisOfSecond(), 0);
    MutableDateTime tempFromTime = fromDate.copy();
    MutableDateTime tempToTime = toDate.copy();

    if (log.isDebugEnabled()) {
        log.debug("Time range: " + formatter.format(fromDate.toDate()) + "->"
                + formatter.format(toDate.toDate()));
    }// w w w .  j av  a2 s. co m

    if (toDate.getMillis() - fromDate.getMillis() < DateTimeConstants.MILLIS_PER_MINUTE) {
        ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                new long[] { fromDate.getMillis(), toDate.getMillis() }));
    } else {
        if (tempFromTime.getSecondOfMinute() != 0
                && (toDate.getMillis() - fromDate.getMillis() > DateTimeConstants.MILLIS_PER_MINUTE)) {
            tempFromTime = tempFromTime.minuteOfHour().roundCeiling();
            ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getMinuteOfHour() != 0
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) {
            fromDate = tempFromTime.copy();
            if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE) < 60) {
                tempFromTime = tempFromTime.minuteOfHour().add(
                        (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_MINUTE);
            } else {
                tempFromTime = tempFromTime.hourOfDay().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.MINUTE.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getHourOfDay() != 0
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) {
            fromDate = tempFromTime.copy();
            if (((toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR) < 24) {
                tempFromTime = tempFromTime.hourOfDay().add(
                        (toDate.getMillis() - tempFromTime.getMillis()) / DateTimeConstants.MILLIS_PER_HOUR);
            } else {
                tempFromTime = tempFromTime.dayOfMonth().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.HOUR.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempFromTime.getDayOfMonth() != 1
                && ((toDate.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) {
            fromDate = tempFromTime.copy();
            if ((((toDate.getMillis() - tempFromTime.getMillis())
                    / DateTimeConstants.MILLIS_PER_DAY)) < tempFromTime.dayOfMonth().getMaximumValue()) {
                tempFromTime = tempFromTime.dayOfMonth().add(((toDate.getMillis() - tempFromTime.getMillis())
                        / ((long) DateTimeConstants.MILLIS_PER_DAY)));
            } else {
                tempFromTime = tempFromTime.monthOfYear().roundCeiling();
            }
            ranges.add(new TimeRange(RangeUnit.DAY.name(),
                    new long[] { fromDate.getMillis(), tempFromTime.getMillis() }));
        }
        if (tempToTime.getSecondOfMinute() != 0
                && (tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_SECOND) {
            toDate = tempToTime.copy();
            long remainingSeconds = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_MINUTE) / DateTimeConstants.MILLIS_PER_SECOND;
            if (remainingSeconds < 60) {
                tempToTime = tempToTime.secondOfMinute().add(-1 * remainingSeconds);

            } else {
                tempToTime = tempToTime.secondOfMinute().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.SECOND.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getMinuteOfHour() != 0 && ((tempToTime.getMillis()
                - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_MINUTE)) {
            toDate = tempToTime.copy();
            long remainingMinutes = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_HOUR) / DateTimeConstants.MILLIS_PER_MINUTE;
            if (remainingMinutes < 60) {
                tempToTime = tempToTime.minuteOfHour().add(-1 * remainingMinutes);
            } else {
                tempToTime = tempToTime.hourOfDay().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.MINUTE.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getHourOfDay() != 0
                && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_HOUR)) {
            toDate = tempToTime.copy();
            long remainingHours = ((toDate.getMillis() - tempFromTime.getMillis())
                    % DateTimeConstants.MILLIS_PER_DAY) / DateTimeConstants.MILLIS_PER_HOUR;
            if (remainingHours < 24) {
                tempToTime = tempToTime.hourOfDay().add(-1 * remainingHours);
            } else {
                tempToTime = tempToTime.dayOfMonth().roundFloor();
            }
            ranges.add(new TimeRange(RangeUnit.HOUR.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.getDayOfMonth() != 1
                && ((tempToTime.getMillis() - tempFromTime.getMillis()) >= DateTimeConstants.MILLIS_PER_DAY)) {
            toDate = tempToTime.copy();
            tempToTime = tempToTime.monthOfYear().roundFloor();
            ranges.add(new TimeRange(RangeUnit.DAY.name(),
                    new long[] { tempToTime.getMillis(), toDate.getMillis() }));
        }
        if (tempToTime.isAfter(tempFromTime)) {
            ranges.add(new TimeRange(RangeUnit.MONTH.name(),
                    new long[] { tempFromTime.getMillis(), tempToTime.getMillis() }));
        }
    }
    if (log.isDebugEnabled()) {
        for (TimeRange timeRange : ranges) {
            log.debug("Unit: " + timeRange.getUnit() + " Range: "
                    + formatter.format(new Date(timeRange.getRange()[0])) + "(" + timeRange.getRange()[0]
                    + ")->" + formatter.format(new Date(timeRange.getRange()[1])) + "("
                    + timeRange.getRange()[1] + ")");
        }
    }
    return ranges;
}