DateTime now = DateTime.now(); DateTime dateTime = now.plusMinutes(10); Seconds seconds = Seconds.secondsBetween(now, dateTime); System.out.println(seconds.getSeconds());
@VisibleForTesting static int parsePeriodToSeconds(String periodStr) { try { return Period.parse(periodStr.toUpperCase(), PERIOD_FORMATTER).toStandardSeconds().getSeconds(); } catch(ArithmeticException ae) { throw new RuntimeException(String.format("Reporting interval is too long. Max: %d seconds.", Integer.MAX_VALUE)); } }
private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId) { BasicQueryInfo queryInfo = queryIdToInfo.get(queryId); if (queryInfo == null) { return true; } DateTime queryEndTime = queryInfo.getQueryStats().getEndTime(); if (queryInfo.getState() == RUNNING || queryEndTime == null) { return false; } return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC; }
public ConvertedTime getConvertedTime(long duration) { Set<Seconds> keys = RULES.keySet(); for (Seconds seconds : keys) { if (duration <= seconds.getSeconds()) { return RULES.get(seconds).getConvertedTime(duration); } } return new TimeConverter.OverTwoYears().getConvertedTime(duration); }
@VisibleForTesting int resolvedSecondsAgo(String streamId, String conditionId) { final Optional<Alert> lastTriggeredAlert = getLastTriggeredAlert(streamId, conditionId); if (!lastTriggeredAlert.isPresent()) { return -1; } final Alert mostRecentAlert = lastTriggeredAlert.get(); final DateTime resolvedAt = mostRecentAlert.getResolvedAt(); if (resolvedAt == null || !isResolved(mostRecentAlert)) { return -1; } return Seconds.secondsBetween(resolvedAt, Tools.nowUTC()).getSeconds(); }
/** * Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a form * suited to the current locale), similar to that used on the call-in-progress * screen. * * See {@link android.text.format.DateUtils#formatElapsedTime} for full docs. * * @param recycle {@link StringBuilder} to recycle, or null to use a temporary one. * @param elapsedDuration the elapsed duration */ public static String formatElapsedTime(StringBuilder recycle, ReadableDuration elapsedDuration) { return android.text.format.DateUtils.formatElapsedTime(recycle, elapsedDuration.toDuration().toStandardSeconds().getSeconds()); }
/** * Calculate the number of seconds in the given time range. * * @param timeRange the {@link TimeRange} * @return the number of seconds in the given time range or 0 if an error occurred. */ public static int toSeconds(TimeRange timeRange) { if (timeRange.getFrom() == null || timeRange.getTo() == null) { return 0; } try { return Seconds.secondsBetween(timeRange.getFrom(), timeRange.getTo()).getSeconds(); } catch (IllegalArgumentException e) { return 0; } } }
@Override public boolean shouldRepeatNotifications(AlertCondition alertCondition, Alert alert) { // Do not repeat notifications if alert has no state, is resolved or the option to repeat notifications is disabled if (!alert.isInterval() || isResolved(alert) || !alertCondition.shouldRepeatNotifications()) { return false; } // Repeat notifications if no grace period is set, avoiding looking through the notification history if (alertCondition.getGrace() == 0) { return true; } AlarmCallbackHistory lastTriggeredAlertHistory = null; for (AlarmCallbackHistory history : alarmCallbackHistoryService.getForAlertId(alert.getId())) { if (lastTriggeredAlertHistory == null || lastTriggeredAlertHistory.createdAt().isBefore(history.createdAt())) { lastTriggeredAlertHistory = history; } } // Repeat notifications if no alert was ever triggered for this condition if (lastTriggeredAlertHistory == null) { return true; } final int lastAlertSecondsAgo = Seconds.secondsBetween(lastTriggeredAlertHistory.createdAt(), Tools.nowUTC()).getSeconds(); return lastAlertSecondsAgo >= alertCondition.getGrace() * 60; }
long count; if (Minutes.minutesIn(interval).isLessThan(Minutes.ONE)) { count = Seconds.secondsIn(interval).getSeconds(); if (past) { if (abbrevRelative) {
private static String getSecondsCron(Period p) { Integer sec = p.getSeconds(); Seconds s = p.toStandardSeconds(); Integer seconds = s.getSeconds(); String str = "0" + (sec > 0 ? "/" + sec : ""); if (seconds > 60) { str = sec + ""; } return str; }
assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(baseDateTime, TIMESTAMP).getSeconds()); assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) minutesBetween(baseDateTime, TIMESTAMP).getMinutes()); assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(baseDateTime, TIMESTAMP).getHours()); assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getSeconds()); assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT,
/** * Translates the given (Joda) Period to duration in seconds. * * @param period the period * @return the duration representing the same amount of time in seconds */ public static long toDuration(Period period) { return period.toStandardSeconds().getSeconds(); }
public Sessionize(String timeSpec) { Period p = new Period("PT" + timeSpec.toUpperCase()); this.millis = p.toStandardSeconds().getSeconds() * 1000; cleanup(); }
@Override public void doUpgrade(final boolean setupMode) throws Exception { final DateTime startedAt = new DateTime(); int deletedGadgets = Delete.from(GADGET_TABLE).whereLike(GADGET_URI_COLUMN, NEWS_GADGET_URI).execute(ofBizDelegator); log.info(String.format("Upgrade task took %d seconds to remove %d news gadgets.", Seconds.secondsBetween(startedAt, new DateTime()).getSeconds(), deletedGadgets)); } }
public void on(DateTime instant, Runnable runnable) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("schedule runnable[%s] on %s", runnable, instant); } DateTime now = DateTime.now(); E.illegalArgumentIf(instant.isBefore(now)); Seconds seconds = Seconds.secondsBetween(now, instant); executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS); }
private void delayedSchedule(JobManager manager, Job job) { DateTime now = DateTime.now(); // add one seconds to prevent the next time be the current time (now) DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1)); Seconds seconds = Seconds.secondsBetween(now, next); ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS); manager.futureScheduled(job.id(), future); }
private int getTTL(MetricId<?> metricId) { Integer ttl = dataRetentions.get(new DataRetentionKey(metricId)); if (ttl == null) { ttl = dataRetentions.getOrDefault(new DataRetentionKey(metricId.getTenantId(), metricId.getType()), defaultTTL); } else { ttl = Duration.standardDays(ttl).toStandardSeconds().getSeconds(); } return ttl; }
private void delayedSchedule(JobManager manager, Job job) { DateTime now = DateTime.now(); // add one seconds to prevent the next time be the current time (now) DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1)); Seconds seconds = Seconds.secondsBetween(now, next); ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS); manager.futureScheduled(job.id(), future); }
private int getTTL(MetricId<?> metricId) { Integer ttl = dataRetentions.get(new DataRetentionKey(metricId)); if (ttl == null) { ttl = dataRetentions.getOrDefault(new DataRetentionKey(metricId.getTenantId(), metricId.getType()), defaultTTL); } else { ttl = Duration.standardDays(ttl).toStandardSeconds().getSeconds(); } return ttl; }
@Test public void testJodaTimePeriod() throws ParseException { String periodText = "PT10m"; Period period = new Period(periodText); int seconds = period.toStandardSeconds().getSeconds(); Assert.assertEquals(600, seconds); Assert.assertEquals(60, period.toStandardSeconds().dividedBy(10).getSeconds()); }