List of usage examples for org.joda.time DateTimeConstants MILLIS_PER_SECOND
int MILLIS_PER_SECOND
To view the source code for org.joda.time DateTimeConstants MILLIS_PER_SECOND.
Click Source Link
From source file:com.music.scheduled.TimelineMusicProcessor.java
License:Open Source License
@Scheduled(fixedDelay = 10 * DateTimeConstants.MILLIS_PER_SECOND) public void run() { try {/*from www .ja v a 2 s . c o m*/ TimelineMusicRequest request = dao.getUnprocessedTimelineMusicRequest(); if (request == null) { return; } long start = System.currentTimeMillis(); TimelineMusic music = service.storeUserTimelinePiece(request.getUser()); service.completeRequest(request, start); sendEmail(music); } catch (Exception ex) { logger.error("Problem processing twitter music request", ex); } }
From source file:com.netflix.spinnaker.igor.health.PollingMonitorHealth.java
License:Apache License
private Predicate<PollingMonitor> hasBeenFiveTimesPollIntervalSinceLastPollPredicate() { return i -> i.getLastPoll() != null && (System.currentTimeMillis() - i.getLastPoll()) > 5 * i.getPollInterval() * DateTimeConstants.MILLIS_PER_SECOND; }
From source file:com.netflix.spinnaker.igor.health.PollingMonitorHealth.java
License:Apache License
private Health getPollingMonitorHealth(PollingMonitor pollingMonitor) { final long elapsed = System.currentTimeMillis() - pollingMonitor.getLastPoll(); // has it been 5 x pollInterval since last poll? if (elapsed > 5 * pollingMonitor.getPollInterval() * DateTimeConstants.MILLIS_PER_SECOND) { log.warn("{} {}msec since last poll, this poller is DOWN", pollingMonitor.getName(), elapsed); return Health.down().withDetail(String.format("%s.status", pollingMonitor.getName()), "stopped") .withDetail(String.format("%s.lastPoll", pollingMonitor.getName()), pollingMonitor.getLastPoll()) .build();// ww w.j a v a2s. co m } return Health.up().withDetail(String.format("%s.status", pollingMonitor.getName()), "running") .withDetail(String.format("%s.lastPoll", pollingMonitor.getName()), pollingMonitor.getLastPoll()) .build(); }
From source file:influent.server.utilities.DateTimeParser.java
License:MIT License
/** * @see http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html#normalizedStandard() */// w w w . j a va2 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.apache.nutch.webui.client.impl.RemoteCommandExecutor.java
License:Apache License
private long getTimeout(RemoteCommand command) { if (command.getTimeout() == null) { return DEFAULT_TIMEOUT_SEC * DateTimeConstants.MILLIS_PER_SECOND; }//from w w w.j av a 2 s. c om return command.getTimeout().getMillis(); }
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 ww .java 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.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 a 2 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())); }/*from ww w .ja v a 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; }
From source file:rcrr.reversi.Clock.java
License:Open Source License
/** * Returns a String representing the clock. * The format is mm:ss corresponding to the given time in milliseconds, where: * - mm is the amount of minutes/* w w w. ja v a2 s .c o m*/ * - ss is the amount of seconds * * @param duration time in milliseconds * @return a formatted {@code String} with minutes and seconds */ private static String timeString(final Duration duration) { final long durationAsMilliseconds = duration.getMillis(); final long durationAsSeconds = durationAsMilliseconds / DateTimeConstants.MILLIS_PER_SECOND; final long minutes = durationAsSeconds / DateTimeConstants.SECONDS_PER_MINUTE; final long seconds = durationAsSeconds - (minutes * DateTimeConstants.SECONDS_PER_MINUTE); return TIME_FORMATTER.format(minutes) + ":" + TIME_FORMATTER.format(seconds); }