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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(257)

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

DateTime.minus介绍

[英]Returns a copy of this datetime with the specified duration taken away.

If the amount is zero or null, then this is returned. This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime的副本,指定的持续时间已结束。
如果金额为零或空,则返回this。此datetime实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: apache/storm

public static DateTime floor(DateTime dateTime, int sec) {
  long modValue = dateTime.getMillis() % (1000 * sec);
  return dateTime.minus(modValue);
}

代码示例来源:origin: apache/incubator-druid

@Override
 public boolean appliesTo(Interval theInterval, DateTime referenceTimestamp)
 {
  final DateTime periodAgo = referenceTimestamp.minus(period);
  return theInterval.getEndMillis() <= periodAgo.getMillis();
 }
}

代码示例来源:origin: apache/storm

public static DateTime ceil(DateTime dateTime, int sec) {
    long modValue = dateTime.getMillis() % (1000 * sec);
    return dateTime.minus(modValue).plusSeconds(sec);
  }
}

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

@Override
  public boolean test(Sidecar sidecar) {
    final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(timeoutPeriod);
    return sidecar.lastSeen().isAfter(threshold);
  }
}

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

private boolean isAbandoned(T query)
{
  DateTime oldestAllowedHeartbeat = DateTime.now().minus(clientTimeout.toMillis());
  DateTime lastHeartbeat = query.getLastHeartbeat();
  return lastHeartbeat != null && lastHeartbeat.isBefore(oldestAllowedHeartbeat);
}

代码示例来源:origin: apache/incubator-druid

Bucket(Interval interval, ArrayList<DataSegment> sortedSegments, double[] leftSum, double[] rightSum)
{
 this.interval = Preconditions.checkNotNull(interval, "interval");
 this.sortedSegments = Preconditions.checkNotNull(sortedSegments, "sortedSegments");
 this.leftSum = Preconditions.checkNotNull(leftSum, "leftSum");
 this.rightSum = Preconditions.checkNotNull(rightSum, "rightSum");
 Preconditions.checkArgument(sortedSegments.size() == leftSum.length && sortedSegments.size() == rightSum.length);
 Preconditions.checkArgument(SEGMENT_ORDERING.isOrdered(sortedSegments));
 this.calculationInterval = new Interval(
   interval.getStart().minus(LIFE_THRESHOLD),
   interval.getEnd().plus(LIFE_THRESHOLD)
 );
}

代码示例来源:origin: apache/incubator-druid

@Override
public List<TaskInfo<Task, TaskStatus>> getRecentlyCreatedAlreadyFinishedTaskInfo(
  @Nullable Integer maxTaskStatuses,
  @Nullable Duration durationBeforeNow,
  @Nullable String datasource
)
{
 return ImmutableList.copyOf(
   handler.getCompletedTaskInfo(
     DateTimes.nowUtc().minus(durationBeforeNow == null ? config.getRecentlyFinishedThreshold() : durationBeforeNow),
     maxTaskStatuses,
     datasource
   )
 );
}

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

public void removeOldTasks()
{
  DateTime oldestAllowedTask = DateTime.now().minus(infoCacheTime.toMillis());
  for (TaskInfo taskInfo : filter(transform(tasks.asMap().values(), SqlTask::getTaskInfo), notNull())) {
    TaskId taskId = taskInfo.getTaskStatus().getTaskId();
    try {
      DateTime endTime = taskInfo.getStats().getEndTime();
      if (endTime != null && endTime.isBefore(oldestAllowedTask)) {
        tasks.asMap().remove(taskId);
      }
    }
    catch (RuntimeException e) {
      log.warn(e, "Error while inspecting age of complete task %s", taskId);
    }
  }
}

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

public int destroyExpired(Period period) {
  final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(period);
  int count;
  try (final Stream<Sidecar> collectorStream = streamAll()) {
    count = collectorStream
        .mapToInt(collector -> {
          if (collector.lastSeen().isBefore(threshold)) {
            return delete(collector.id());
          }
          return 0;
        })
        .sum();
  }
  return count;
}

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

@Override
@JsonIgnore
public DateTime getFrom() {
  // TODO this should be computed once
  if (range() > 0) {
    return Tools.nowUTC().minus(Seconds.seconds(range()));
  }
  return new DateTime(0, DateTimeZone.UTC);
}

代码示例来源:origin: apache/incubator-druid

@VisibleForTesting
 Interval findIntervalForKillTask(String dataSource, int limit)
 {
  List<Interval> unusedSegmentIntervals = segmentManager.getUnusedSegmentIntervals(
    dataSource,
    new Interval(DateTimes.EPOCH, DateTimes.nowUtc().minus(retainDuration)),
    limit
  );

  if (unusedSegmentIntervals != null && unusedSegmentIntervals.size() > 0) {
   return JodaUtils.umbrellaInterval(unusedSegmentIntervals);
  } else {
   return null;
  }
 }
}

代码示例来源:origin: apache/incubator-druid

private Interval getIntervalOrDefault(Interval interval)
{
 final Interval theInterval;
 if (interval == null) {
  DateTime now = DateTimes.nowUtc();
  theInterval = new Interval(now.minus(config.getAuditHistoryMillis()), now);
 } else {
  theInterval = interval;
 }
 return theInterval;
}

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

protected org.graylog2.plugin.indexer.searches.timeranges.TimeRange restrictTimeRange(final org.graylog2.plugin.indexer.searches.timeranges.TimeRange timeRange) {
  final DateTime originalFrom = timeRange.getFrom();
  final DateTime to = timeRange.getTo();
  final DateTime from;
  final SearchesClusterConfig config = clusterConfigService.get(SearchesClusterConfig.class);
  if (config == null || Period.ZERO.equals(config.queryTimeRangeLimit())) {
    from = originalFrom;
  } else {
    final DateTime limitedFrom = to.minus(config.queryTimeRangeLimit());
    from = limitedFrom.isAfter(originalFrom) ? limitedFrom : originalFrom;
  }
  return AbsoluteRange.create(from, to);
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testAccept()
 {
  Period period = new Period("PT10M");

  RejectionPolicy rejectionPolicy = new ServerTimeRejectionPolicyFactory().create(period);

  DateTime now = DateTimes.nowUtc();
  DateTime past = now.minus(period).minus(100);
  DateTime future = now.plus(period).plus(100);

  Assert.assertTrue(rejectionPolicy.accept(now.getMillis()));
  Assert.assertFalse(rejectionPolicy.accept(past.getMillis()));
  Assert.assertFalse(rejectionPolicy.accept(future.getMillis()));
 }
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testAccept()
 {
  Period period = new Period("PT10M");
  RejectionPolicy rejectionPolicy = new MessageTimeRejectionPolicyFactory().create(period);

  DateTime now = DateTimes.nowUtc();
  DateTime past = now.minus(period).minus(1);
  DateTime future = now.plus(period).plus(1);

  Assert.assertTrue(rejectionPolicy.accept(now.getMillis()));
  Assert.assertFalse(rejectionPolicy.accept(past.getMillis()));
  Assert.assertTrue(rejectionPolicy.accept(future.getMillis()));
  Assert.assertFalse(rejectionPolicy.accept(now.getMillis()));
 }
}

代码示例来源:origin: apache/incubator-druid

@Override
public Interval getDataInterval()
{
 return new Interval(DateTimes.nowUtc().minus(Days.days(1)), DateTimes.nowUtc());
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testUnUsedOverlapLow() throws IOException
{
 coordinator.announceHistoricalSegments(SEGMENTS);
 unUseSegment();
 Assert.assertTrue(
   coordinator.getUnusedSegmentsForInterval(
     defaultSegment.getDataSource(),
     new Interval(
       defaultSegment.getInterval().getStart().minus(1),
       defaultSegment.getInterval().getStart().plus(1)
     )
   ).isEmpty()
 );
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testUnUsedOverlapHigh() throws IOException
{
 coordinator.announceHistoricalSegments(SEGMENTS);
 unUseSegment();
 Assert.assertTrue(
   coordinator.getUnusedSegmentsForInterval(
     defaultSegment.getDataSource(),
     defaultSegment.getInterval().withStart(defaultSegment.getInterval().getEnd().minus(1))
   ).isEmpty()
 );
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testUsedOutOfBoundsLow() throws IOException
{
 coordinator.announceHistoricalSegments(SEGMENTS);
 Assert.assertTrue(
   coordinator.getUsedSegmentsForInterval(
     defaultSegment.getDataSource(),
     new Interval(defaultSegment.getInterval().getStart().minus(1), defaultSegment.getInterval().getStart())
   ).isEmpty()
 );
}

代码示例来源:origin: apache/incubator-druid

@Test
public void testUnUsedUnderlapHigh() throws IOException
{
 coordinator.announceHistoricalSegments(SEGMENTS);
 unUseSegment();
 Assert.assertTrue(
   coordinator.getUnusedSegmentsForInterval(
     defaultSegment.getDataSource(),
     new Interval(defaultSegment.getInterval().getStart(), defaultSegment.getInterval().getEnd().minus(1))
   ).isEmpty()
 );
}

相关文章

DateTime类方法