Refine search
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; }
/** * Returns a new instance with the specified number of seconds taken away. * <p> * This instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to take away, may be negative * @return the new period minus the specified number of seconds * @throws ArithmeticException if the result overflows an int */ public Seconds minus(int seconds) { return plus(FieldUtils.safeNegate(seconds)); }
/** * Returns a new instance with the specified number of seconds added. * <p> * This instance is immutable and unaffected by this method call. * * @param seconds the amount of seconds to add, may be negative, null means zero * @return the new period plus the specified number of seconds * @throws ArithmeticException if the result overflows an int */ public Seconds plus(Seconds seconds) { if (seconds == null) { return this; } return plus(seconds.getValue()); }
/** * Returns a new instance with the seconds multiplied by the specified scalar. * <p> * This instance is immutable and unaffected by this method call. * * @param scalar the amount to multiply by, may be negative * @return the new period multiplied by the specified scalar * @throws ArithmeticException if the result overflows an int */ public Seconds multipliedBy(int scalar) { return Seconds.seconds(FieldUtils.safeMultiply(getValue(), scalar)); }
@RequiresServiceRole(roleName = "WRITE") public void cleanCache() { final DateTime now = new DateTime(); for (Iterator<Map.Entry<String, MetadataNearRealtimeCacheEntry>> itr = cache.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, MetadataNearRealtimeCacheEntry> entry = itr.next(); DateTime entryTime = new DateTime(entry.getValue().getTimestamp()); final Seconds seconds = Seconds.secondsBetween(entryTime, now); if (seconds.getSeconds() > thresholdInSeconds) { itr.remove(); } } }
DateTime now = DateTime.now(time.getZone()).withMillisOfSecond(0); DateTime timeDt = new DateTime(time).withMillisOfSecond(0); boolean past = !now.isBefore(timeDt); Interval interval = past ? new Interval(timeDt, now) : new Interval(now, timeDt); if (Minutes.minutesIn(interval).isLessThan(Minutes.ONE)) { count = Seconds.secondsIn(interval).getSeconds(); if (past) { if (abbrevRelative) { else if (Hours.hoursIn(interval).isLessThan(Hours.ONE)) { count = Minutes.minutesIn(interval).getMinutes(); if (past) { if (abbrevRelative) { count = Hours.hoursIn(interval).getHours(); if (past) { if (abbrevRelative) {
@Test public void testDateDiffTime() { DateTime baseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, DATE_TIME_ZONE); String baseDateTimeLiteral = "TIME '07:02:09.678'"; assertFunction("date_diff('millisecond', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, millisBetween(baseDateTime, TIME)); assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, secondsBetween(baseDateTime, TIME).getSeconds()); assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, minutesBetween(baseDateTime, TIME).getMinutes()); assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, hoursBetween(baseDateTime, TIME).getHours()); DateTime weirdBaseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, WEIRD_ZONE); String weirdBaseDateTimeLiteral = "TIME '07:02:09.678 +07:09'"; assertFunction("date_diff('millisecond', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, millisBetween(weirdBaseDateTime, WEIRD_TIME)); assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, secondsBetween(weirdBaseDateTime, WEIRD_TIME).getSeconds()); assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, minutesBetween(weirdBaseDateTime, WEIRD_TIME).getMinutes()); assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, hoursBetween(weirdBaseDateTime, WEIRD_TIME).getHours()); }
@Test public void testDateDiffTimestamp() DateTime baseDateTime = new DateTime(1960, 5, 3, 7, 2, 9, 678, isLegacyTimestamp(session) ? DATE_TIME_ZONE : UTC_TIME_ZONE); String baseDateTimeLiteral = "TIMESTAMP '1960-05-03 07:02:09.678'"; 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('day', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) daysBetween(baseDateTime, TIMESTAMP).getDays()); assertFunction("date_diff('week', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) weeksBetween(baseDateTime, TIMESTAMP).getWeeks()); assertFunction("date_diff('year', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) yearsBetween(baseDateTime, TIMESTAMP).getYears()); DateTime weirdBaseDateTime = new DateTime(1960, 5, 3, 7, 2, 9, 678, WEIRD_DATE_TIME_ZONE); String weirdBaseDateTimeLiteral = "TIMESTAMP '1960-05-03 07:02:09.678 +07:09'"; assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getSeconds()); assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) minutesBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getMinutes()); assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getHours()); assertFunction("date_diff('day', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")", BIGINT,
public <T> Future<T> on(DateTime instant, Callable<T> callable) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("schedule callable[%s] on %s", callable, instant); } DateTime now = DateTime.now(); E.illegalArgumentIf(instant.isBefore(now)); Seconds seconds = Seconds.secondsBetween(now, instant); return executor().schedule(callable, 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); }
/** * Converts this period to a period in seconds assuming a * 7 day week, 24 hour day, 60 minute hour and 60 second minute. * <p> * This method allows you to convert between different types of period. * However to achieve this it makes the assumption that all * weeks are 7 days, all days are 24 hours, all hours are 60 minutes and * all minutes are 60 seconds. This is not true when daylight savings time * is considered, and may also not be true for some unusual chronologies. * However, it is included as it is a useful operation for many * applications and business rules. * <p> * If the period contains years or months, an exception will be thrown. * * @return a period representing the number of standard seconds in this period * @throws UnsupportedOperationException if the period contains years or months * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.5 */ public Seconds toStandardSeconds() { checkYearsAndMonths("Seconds"); long seconds = getMillis() / DateTimeConstants.MILLIS_PER_SECOND; seconds = FieldUtils.safeAdd(seconds, getSeconds()); seconds = FieldUtils.safeAdd(seconds, ((long) getMinutes()) * ((long) DateTimeConstants.SECONDS_PER_MINUTE)); seconds = FieldUtils.safeAdd(seconds, ((long) getHours()) * ((long) DateTimeConstants.SECONDS_PER_HOUR)); seconds = FieldUtils.safeAdd(seconds, ((long) getDays()) * ((long) DateTimeConstants.SECONDS_PER_DAY)); seconds = FieldUtils.safeAdd(seconds, ((long) getWeeks()) * ((long) DateTimeConstants.SECONDS_PER_WEEK)); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
@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; }
public Sessionize(String timeSpec) { Period p = new Period("PT" + timeSpec.toUpperCase()); this.millis = p.toStandardSeconds().getSeconds() * 1000; cleanup(); }
DateTime now = DateTime.now(); DateTime dateTime = now.plusMinutes(10); Seconds seconds = Seconds.secondsBetween(now, dateTime); System.out.println(seconds.getSeconds());
@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()); }
/** * Converts seconds to mins. * * @param seconds to be converted. * @return mins equivalent of seconds */ public static int SECONDS_TO_MINUTES(int seconds) { Period period = new Period(Seconds.seconds(seconds)); return period.toStandardMinutes().getMinutes(); }
/** * Converts seconds to hours. * * @param seconds to be converted. * @return hours equivalent of seconds */ public static int SECONDS_TO_HOURS(int seconds) { Period period = new Period(Seconds.seconds(seconds)); return period.toStandardHours().getHours(); }