org.joda.time.Seconds.secondsBetween()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中org.joda.time.Seconds.secondsBetween()方法的一些代码示例,展示了Seconds.secondsBetween()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Seconds.secondsBetween()方法的具体详情如下:
包路径:org.joda.time.Seconds
类名称:Seconds
方法名:secondsBetween

Seconds.secondsBetween介绍

[英]Creates a Seconds representing the number of whole seconds between the two specified datetimes.
[中]创建一个Seconds,表示两个指定日期时间之间的整秒数。

代码示例

代码示例来源:origin: prestodb/presto

private static Seconds secondsBetween(ReadableInstant start, ReadableInstant end)
{
  return Seconds.secondsBetween(start, end);
}

代码示例来源:origin: prestodb/presto

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;
}

代码示例来源:origin: Graylog2/graylog2-server

@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();
}

代码示例来源:origin: Graylog2/graylog2-server

/**
   * 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;
    }
  }
}

代码示例来源:origin: Graylog2/graylog2-server

@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;
}

代码示例来源:origin: sanity/quickml

private static double computeReservationTime(String startTime, String endTime) {
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss");
    DateTime startDateTime = dateFormatter.parseDateTime(startTime.substring(0, 19));
    DateTime endDateTime = dateFormatter.parseDateTime(endTime.substring(0,19));
    return ((double) Seconds.secondsBetween(startDateTime, endDateTime).getSeconds())/(24.0*60*60);
  }
}

代码示例来源:origin: Jasig/uPortal

protected EventProcessingResult(int processed, DateTime start, DateTime end, boolean complete) {
  this.processed = processed;
  this.start = start;
  this.end = end;
  this.complete = complete;
  if (start == null || end == null) {
    creationRate = 0;
  } else {
    creationRate =
        (double) processed / Math.abs(Seconds.secondsBetween(start, end).getSeconds());
  }
}

代码示例来源:origin: io.prestosql/presto-main

private static Seconds secondsBetween(ReadableInstant start, ReadableInstant end)
{
  return Seconds.secondsBetween(start, end);
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@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();
    }
  }
}

代码示例来源:origin: qcadoo/mes

private void calculateLaborTime(FieldComponent laborTimeFieldComponent, Optional<Date> from, Optional<Date> to) {
  if (from.isPresent() && to.isPresent() && from.get().before(to.get())) {
    Seconds seconds = Seconds.secondsBetween(new DateTime(from.get()), new DateTime(to.get()));
    laborTimeFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds()));
    laborTimeFieldComponent.requestComponentUpdateState();
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@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));
  }
}

代码示例来源:origin: prestosql/presto

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;
}

代码示例来源:origin: actframework/actframework

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);
}

代码示例来源:origin: io.prestosql/presto-main

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;
}

代码示例来源:origin: actframework/actframework

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);
}

代码示例来源:origin: org.actframework/act

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);
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

protected boolean isOlderThanThreshold(MailMessage message, DateTime now) {
  if(message.hasHeader(MailMessageHeaderNames.MESSAGE_MOVE_TIME)){
    final String moveTime = message.getHeaderVal(MailMessageHeaderNames.MESSAGE_MOVE_TIME);
    final DateTime moveTimeAsDate = new DateTime(moveTime);
    final Seconds seconds = Seconds.secondsBetween(moveTimeAsDate, now);
    if(seconds.getSeconds() > getThresholdInSeconds()){
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.actframework/act

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);
}

代码示例来源:origin: actframework/actframework

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);
}

代码示例来源:origin: com.ning.billing/killbill-meter

@Test(groups = "fast")
  public void testRoundTrip() throws Exception {
    final DateTime utcNow = clock.getUTCNow();
    final int unixSeconds = DateTimeUtils.unixSeconds(utcNow);
    final DateTime dateTimeFromUnixSeconds = DateTimeUtils.dateTimeFromUnixSeconds(unixSeconds);

    Assert.assertEquals(Seconds.secondsBetween(dateTimeFromUnixSeconds, utcNow).getSeconds(), 0);
  }
}

相关文章