Java Code Examples for org.joda.time.DateTime#equals()

The following examples show how to use org.joda.time.DateTime#equals() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static boolean ifRangeHeaderMatches(final Response response, final String ifRangeHeader) {
  // If the if-range header starts with " it is an ETag
  if (ifRangeHeader.startsWith("\"")) {
    String responseEtagHeader = getHeaderValue(response, HttpHeaders.ETAG);
    return ifRangeHeader.equals(responseEtagHeader);
  }

  // Otherwise, it is the last-modified date and time
  DateTime ifRangeHeaderDateTimeValue = parseDateTime(ifRangeHeader);
  if (ifRangeHeaderDateTimeValue != null) {
    DateTime responseLastModifiedHeader = parseDateTime(getHeaderValue(response, HttpHeaders.LAST_MODIFIED));
    return ifRangeHeaderDateTimeValue.equals(responseLastModifiedHeader);
  }
  else {
    return false;
  }
}
 
Example 2
private void updateLastExecutionDate(DateTime lastExecutionDate, DateTime newExecutionDate) {
    if (!newExecutionDate.equals(lastExecutionDate)) {
        view.setLastExecutionDate(newExecutionDate);
        view.saveExecutionDateToPreferencesAsString();
        view.updateDescription();
    }
}
 
Example 3
public static boolean shouldJobRun(JobSpec aJob, DateTime now) {
  if (aJob.getParent() != null || aJob.isEnabled() == false) {
    return false;
  }
  CronExpression ce = CronExpression.createWithoutSeconds(aJob.getCronString());
  DateTime next = ce.nextTimeAfter(now.minusMinutes(1));
  return next.equals(now);
}
 
Example 4
/**
 * Loads the diff keys for one bucket.
 *
 * @param lowerCheckpoint exclusive lower bound on keys in this diff, or null if no lower bound
 * @param upperCheckpoint inclusive upper bound on keys in this diff
 * @param bucketNum the bucket to load diff keys from
 */
private Iterable<Key<CommitLogManifest>> loadDiffKeysFromBucket(
    @Nullable CommitLogCheckpoint lowerCheckpoint,
    CommitLogCheckpoint upperCheckpoint,
    int bucketNum) {
  // If no lower checkpoint exists, or if it exists but had no timestamp for this bucket number
  // (because the bucket count was increased between these checkpoints), then use START_OF_TIME
  // as the effective exclusive lower bound.
  DateTime lowerCheckpointBucketTime =
      firstNonNull(
          (lowerCheckpoint == null) ? null : lowerCheckpoint.getBucketTimestamps().get(bucketNum),
          START_OF_TIME);
  // Since START_OF_TIME=0 is not a valid id in a key, add 1 to both bounds. Then instead of
  // loading lowerBound < x <= upperBound, we can load lowerBound <= x < upperBound.
  DateTime lowerBound = lowerCheckpointBucketTime.plusMillis(1);
  DateTime upperBound = upperCheckpoint.getBucketTimestamps().get(bucketNum).plusMillis(1);
  // If the lower and upper bounds are equal, there can't be any results, so skip the query.
  if (lowerBound.equals(upperBound)) {
    return ImmutableSet.of();
  }
  Key<CommitLogBucket> bucketKey = getBucketKey(bucketNum);
  return ofy().load()
      .type(CommitLogManifest.class)
      .ancestor(bucketKey)
      .filterKey(">=", CommitLogManifest.createKey(bucketKey, lowerBound))
      .filterKey("<", CommitLogManifest.createKey(bucketKey, upperBound))
      .keys();
}
 
Example 5
Source Project: nomulus   File: CommitLogExports.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads the diff keys for one bucket.
 *
 * @param lowerCheckpoint exclusive lower bound on keys in this diff, or null if no lower bound
 * @param upperCheckpoint inclusive upper bound on keys in this diff
 * @param bucketNum the bucket to load diff keys from
 */
private static Iterable<Key<CommitLogManifest>> loadDiffKeysFromBucket(
    @Nullable CommitLogCheckpoint lowerCheckpoint,
    CommitLogCheckpoint upperCheckpoint,
    int bucketNum) {
  // If no lower checkpoint exists, or if it exists but had no timestamp for this bucket number
  // (because the bucket count was increased between these checkpoints), then use START_OF_TIME
  // as the effective exclusive lower bound.
  DateTime lowerCheckpointBucketTime =
      firstNonNull(
          (lowerCheckpoint == null) ? null : lowerCheckpoint.getBucketTimestamps().get(bucketNum),
          START_OF_TIME);
  // Since START_OF_TIME=0 is not a valid id in a key, add 1 to both bounds. Then instead of
  // loading lowerBound < x <= upperBound, we can load lowerBound <= x < upperBound.
  DateTime lowerBound = lowerCheckpointBucketTime.plusMillis(1);
  DateTime upperBound = upperCheckpoint.getBucketTimestamps().get(bucketNum).plusMillis(1);
  // If the lower and upper bounds are equal, there can't be any results, so skip the query.
  if (lowerBound.equals(upperBound)) {
    return ImmutableSet.of();
  }
  Key<CommitLogBucket> bucketKey = getBucketKey(bucketNum);
  return ofy()
      .load()
      .type(CommitLogManifest.class)
      .ancestor(bucketKey)
      .filterKey(">=", CommitLogManifest.createKey(bucketKey, lowerBound))
      .filterKey("<", CommitLogManifest.createKey(bucketKey, upperBound))
      .keys();
}
 
Example 6
public List<SiteActivities> getLastFiveDaysOfActivity() {
    List<SiteActivities> result = Lists.newArrayList();

    SiteActivity pivot = getLastActivityLine();
    DateTime current = null;
    List<SiteActivity> day = null;

    while (pivot != null) {
        DateTime date = pivot.getEventDate();

        if (!date.equals(current)) {
            if (result.size() != 5) {
                day = Lists.newArrayList();
                SiteActivities sas = new SiteActivities();
                sas.setItems(day);
                sas.setDate(date);
                result.add(0, sas);
                current = date;
            } else {
                break;
            }
        }

        day.add(0, pivot);

        pivot = pivot.getPrevious();
    }

    return result.subList(0, Math.min(result.size(), 10));
}
 
Example 7
Source Project: spork   File: TestPOBinCond.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPOBinCondWithDateTime() throws  ExecException, PlanException {
    bag= getBag(DataType.DATETIME);
    TestPoBinCondHelper testHelper= new TestPoBinCondHelper(DataType.DATETIME, new DateTime(1L) );

    for (Tuple t : bag) {
       testHelper.getPlan().attachInput(t);
       DateTime value = (DateTime) t.get(0);
       int expected = value.equals(new DateTime(1L))? 1:0 ;
       Integer dummy = new Integer(0);
       Integer result=(Integer)testHelper.getOperator().getNextInteger().result;
       int actual = result.intValue();
       assertEquals( expected, actual );
    }
}
 
Example 8
Source Project: java   File: ProcessorListener.java    License: Apache License 2.0 4 votes vote down vote up
public boolean shouldResync(DateTime now) {
  return this.resyncPeriod != 0 && (now.isAfter(this.nextResync) || now.equals(this.nextResync));
}
 
Example 9
Source Project: nomulus   File: GenerateZoneFilesAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> handleJsonRequest(Map<String, ?> json) {
  @SuppressWarnings("unchecked")
  ImmutableSet<String> tlds = ImmutableSet.copyOf((List<String>) json.get("tlds"));
  final DateTime exportTime = DateTime.parse(json.get("exportTime").toString());
  // We disallow exporting within the past 2 minutes because there might be outstanding writes.
  // We can only reliably call loadAtPointInTime at times that are UTC midnight and >
  // datastoreRetention ago in the past.
  DateTime now = clock.nowUtc();
  if (exportTime.isAfter(now.minusMinutes(2))) {
    throw new BadRequestException("Invalid export time: must be > 2 minutes ago");
  }
  if (exportTime.isBefore(now.minus(datastoreRetention))) {
    throw new BadRequestException(String.format(
        "Invalid export time: must be < %d days ago",
        datastoreRetention.getStandardDays()));
  }
  if (!exportTime.equals(exportTime.toDateTime(UTC).withTimeAtStartOfDay())) {
    throw new BadRequestException("Invalid export time: must be midnight UTC");
  }
  String mapreduceConsoleLink =
      mrRunner
          .setJobName("Generate bind file stanzas")
          .setModuleName("tools")
          .setDefaultReduceShards(tlds.size())
          .runMapreduce(
              new GenerateBindFileMapper(
                  tlds, exportTime, dnsDefaultATtl, dnsDefaultNsTtl, dnsDefaultDsTtl),
              new GenerateBindFileReducer(bucket, exportTime, gcsBufferSize),
              ImmutableList.of(new NullInput<>(), createEntityInput(DomainBase.class)))
          .getLinkToMapreduceConsole();
  ImmutableList<String> filenames =
      tlds.stream()
          .map(
              tld ->
                  String.format(
                      GCS_PATH_FORMAT, bucket, String.format(FILENAME_FORMAT, tld, exportTime)))
          .collect(toImmutableList());
  return ImmutableMap.of(
      "mapreduceConsoleLink", mapreduceConsoleLink,
      "filenames", filenames);
}
 
Example 10
Source Project: arctic-sea   File: GmlHelper.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Create {@link Time} from {@link DateTime}s
 *
 * @param start
 *            Start {@link DateTime}
 * @param end
 *            End {@link DateTime}
 * @return Resulting {@link Time}
 */
public static Time createTime(DateTime start, DateTime end) {
    if (start.equals(end)) {
        return new TimeInstant(start);
    } else {
        return new TimePeriod(start, end);
    }
}