Example usage for org.joda.time DateTimeConstants MILLIS_PER_MINUTE

List of usage examples for org.joda.time DateTimeConstants MILLIS_PER_MINUTE

Introduction

In this page you can find the example usage for org.joda.time DateTimeConstants MILLIS_PER_MINUTE.

Prototype

int MILLIS_PER_MINUTE

To view the source code for org.joda.time DateTimeConstants MILLIS_PER_MINUTE.

Click Source Link

Document

Milliseconds in one minute (ISO)

Usage

From source file:com.addthis.hydra.job.spawn.JobOnFinishStateHandlerImpl.java

License:Apache License

private void emailNotification(String jobId, JobOnFinishState state, String body) {
    if (backgroundEmailAddress != null) {
        long currentTime = System.currentTimeMillis();
        long lastTime = emailLastFired.get();
        long elapse = currentTime - lastTime;
        if (elapse > (long) backgroundEmailMinute * DateTimeConstants.MILLIS_PER_MINUTE) {
            EmailUtil.email(backgroundEmailAddress, emailSubject(jobId, state), body);
            emailLastFired.set(currentTime);
        }/*from   w  w w  .  j  a  v a  2s  . c o  m*/
    }
}

From source file:com.music.scheduled.MusicGenerationJob.java

License:Open Source License

@Scheduled(fixedDelay = 12 * DateTimeConstants.MILLIS_PER_MINUTE)
public void generate() {
    if (sharedData.isGenerateMusic()) {
        logger.info("Starting piece generation");
        //TODO more precise adjustment this according to users' listening activity
        int piecesNeeded = sharedData.isAdaptGenerationQuantity()
                && sharedData.getListeningRequests().get() > 10 ? 3 : 1;
        for (int i = 0; i < piecesNeeded; i++) {
            long id = service.generatePiece();
            sharedData.setMaxId(id);//from ww  w . j  a  v  a 2s . c  om
        }
        // reset
        sharedData.getListeningRequests().set(0);
    }
}

From source file:influent.server.utilities.DateTimeParser.java

License:MIT License

/**
 * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html#normalizedStandard()
 *///from  w  ww .  j  a v  a  2  s  .co m
public static Period normalize(Period period) {
    long millis = period.getMillis();
    millis += period.getSeconds() * DateTimeConstants.MILLIS_PER_SECOND;
    millis += period.getMinutes() * DateTimeConstants.MILLIS_PER_MINUTE;
    millis += period.getHours() * DateTimeConstants.MILLIS_PER_HOUR;
    millis += period.getDays() * DateTimeConstants.MILLIS_PER_DAY;
    millis += period.getWeeks() * DateTimeConstants.MILLIS_PER_WEEK;

    Period result = new Period(millis, DateTimeUtils.getPeriodType(PeriodType.standard()),
            ISOChronology.getInstanceUTC());
    int years = period.getYears();
    int months = period.getMonths();

    if (years != 0 || months != 0) {
        years = FieldUtils.safeAdd(years, months / 12);
        months = months % 12;
        if (years != 0) {
            result = result.withYears(years);
        }
        if (months != 0) {
            result = result.withMonths(months);
        }
    }

    return result;
}

From source file:org.integratedmodelling.time.literals.DurationValue.java

License:Open Source License

/**
 * Localize a duration to an extent starting at the current moment
 * using the same resolution that was implied in the generating 
 * text. For example, if the duration was one year, localize to the 
 * current year (jan 1st to dec 31st). Return the start and end points
 * of the extent.//w w  w.j a  v a 2s .co m
 * 
 * @return
 */
public Pair<TimeValue, TimeValue> localize() {

    DateTime date = new DateTime();
    TimeValue start = null, end = null;
    long val = value;

    switch (precision) {

    case TemporalPrecision.MILLISECOND:
        start = new TimeValue(date);
        end = new TimeValue(date.plus(val));
        break;
    case TemporalPrecision.SECOND:
        val = value / DateTimeConstants.MILLIS_PER_SECOND;
        start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                date.getHourOfDay(), date.getMinuteOfHour(), date.getSecondOfMinute(), 0));
        end = new TimeValue(start.getTimeData().plusSeconds((int) val));
        break;
    case TemporalPrecision.MINUTE:
        val = value / DateTimeConstants.MILLIS_PER_MINUTE;
        start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                date.getHourOfDay(), date.getMinuteOfHour(), 0, 0));
        end = new TimeValue(start.getTimeData().plusMinutes((int) val));
        break;
    case TemporalPrecision.HOUR:
        val = value / DateTimeConstants.MILLIS_PER_HOUR;
        start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                date.getHourOfDay(), 0, 0, 0));
        end = new TimeValue(start.getTimeData().plusHours((int) val));
        break;
    case TemporalPrecision.DAY:
        val = value / DateTimeConstants.MILLIS_PER_DAY;
        start = new TimeValue(
                new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0, 0));
        end = new TimeValue(start.getTimeData().plusDays((int) val));
        break;
    case TemporalPrecision.MONTH:
        start = new TimeValue(new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0, 0));
        end = new TimeValue(start.getTimeData().plusMonths(origQuantity));
        break;
    case TemporalPrecision.YEAR:
        start = new TimeValue(new DateTime(date.getYear(), 1, 1, 0, 0, 0, 0));
        end = new TimeValue(start.getTimeData().plusYears(origQuantity));
        break;
    }

    return new Pair<TimeValue, TimeValue>(start, end);
}

From source file:org.wannatrak.server.SubjectServiceImpl.java

License:Apache License

private SubjectState getSubjectState(Subject subject) {
    if (StringHelper.isAlmostEmpty(subject.getDeviceId())) {
        return SubjectState.SWITCHED_OFF;
    }/*from  w ww. j a  va 2s. c  o m*/
    final DeviceSettings deviceSettings = subject.getDeviceSettings();
    if (deviceSettings == null) {
        return SubjectState.SWITCHED_OFF;
    }
    final Integer sendPeriod = deviceSettings.getSendPeriod();
    if (sendPeriod == null) {
        return SubjectState.SWITCHED_OFF;
    }
    final DateTime lastUpdated = subject.getLastUpdated();
    if (lastUpdated == null || new DateTime().minus(lastUpdated.getMillis()).getMillis() >= sendPeriod
            * DateTimeConstants.MILLIS_PER_MINUTE * 2) {
        return SubjectState.CONNECTION_FAILED;
    }

    final Position position = subject.getPosition();
    if (position == null) {
        return SubjectState.LOCATION_NOT_DEFINED;
    }

    return SubjectState.TRACKING;
}

From source file:org.wannatrak.ShowServlet.java

License:Apache License

private void addFlag(StringBuilder sb, Position position, int timezoneOffset, String format) {
    final DateTime timestamp = new DateTime(
            position.getGpsTimestamp().getMillis() - timezoneOffset * DateTimeConstants.MILLIS_PER_MINUTE);

    final ResourceBundle resourceBundle = ResourceBundle.getBundle("WEB-INF/classes/org/wannatrak/messages",
            UserSession.getLocale());//  w  w  w . j ava 2 s  .  c om
    sb.append("<Placemark><name>").append(position.getSubject().getName()).append(" ")
            .append(timestamp.toString(format));

    final Double speed = position.getSpeed();
    if (speed != null) {
        sb.append(" ").append(resourceBundle.getString("details")).append(" ")
                .append(String.format("%3.1f", speed)).append(" ").append(resourceBundle.getString("kmh"));
    }

    final Double altitude = position.getAltitude();
    if (altitude != null) {
        sb.append(", ").append(altitude.intValue()).append(" ").append(resourceBundle.getString("masl"));
    }

    sb.append("</name>\n" + "<IconStyle>\n" + "<Icon>\n"
            + "<href>http://maps.google.com/mapfiles/kml/pal3/icon61.png</href>\n" + "</Icon>\n"
            + "</IconStyle>\n" + "<Point><coordinates>\n").append(position.getLongitude()).append(",")
            .append(position.getLatitude()).append("\n").append("</coordinates></Point></Placemark>");
}

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()));
    }/*from   w  w w . j av a2  s.c om*/

    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()));
    }//from w w w  .ja  va 2  s .  c o 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;
}