/** * Convenience method to measure elapsed time between start of query execution and completion or exception as appropriate. Do not call with a null argument or before a query has executed/exploded. * @param unit the time unit to convert to * @return the elapsed time in the given unit */ public long getElapsedTime(ChronoUnit unit) { return unit.between(executionMoment, completionMoment == null ? exceptionMoment : completionMoment); }
public long getDurationInMinutes() { return ChronoUnit.MINUTES.between(departureUTCDateTime, arrivalUTCDateTime); }
/** * Compute the number of calendar days elapsed since the given date. * As it's only the calendar days difference that matter, "11.00pm" to "2.00am the day after" returns 1, * even if there are only 3 hours between. As well as "10am" to "2pm" both on the same day, returns 0. */ @Restricted(NoExternalUse.class) public static long daysBetween(@Nonnull Date a, @Nonnull Date b){ LocalDate aLocal = a.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate bLocal = b.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); return ChronoUnit.DAYS.between(aLocal, bLocal); }
private static long diffDays(LocalDate to) { return ChronoUnit.DAYS.between(LocalDate.now(), to); }
private boolean validateIfModifiedSince(Instant lastModified) { if (lastModified.isBefore(Instant.EPOCH)) { return false; } long ifModifiedSince = getRequestHeaders().getIfModifiedSince(); if (ifModifiedSince == -1) { return false; } // We will perform this validation... this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0; return true; }
private boolean validateIfModifiedSince(Instant lastModified) { if (lastModified.isBefore(Instant.EPOCH)) { return false; } long ifModifiedSince = getRequestHeaders().getIfModifiedSince(); if (ifModifiedSince == -1) { return false; } // We will perform this validation... this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0; return true; }
public long getDaysAfterBusDeparture() { return DAYS.between(bus.getDepartureDate(), date); }
private static long toDays(int year, int month, int day) { return DAYS.between(LocalDate.of(1970, 1, 1), LocalDate.of(year, month, day)); }
public static long minutesUntil(long packedDateTimeEnd, long packedDateTimeStart) { return ChronoUnit.MINUTES.between(asLocalDateTime(packedDateTimeStart), asLocalDateTime(packedDateTimeEnd)); }
private boolean isValidOn(EdgeIteratorState edge, long instant) { GtfsStorage.EdgeType edgeType = flagEncoder.getEdgeType(edge.getFlags()); if (edgeType == GtfsStorage.EdgeType.BOARD || edgeType == GtfsStorage.EdgeType.ALIGHT) { final int validityId = flagEncoder.getValidityId(edge.getFlags()); final GtfsStorage.Validity validity = realtimeFeed.getValidity(validityId); final int trafficDay = (int) ChronoUnit.DAYS.between(validity.start, Instant.ofEpochMilli(instant).atZone(validity.zoneId).toLocalDate()); return trafficDay >= 0 && validity.validity.get(trafficDay); } else { return true; } }
public static long hoursUntil(long packedDateTimeEnd, long packedDateTimeStart) { return ChronoUnit.HOURS.between(asLocalDateTime(packedDateTimeStart), asLocalDateTime(packedDateTimeEnd)); }
/** * Set the transient property at load time based on a calculation. * Note that a native Hibernate formula mapping is better for this purpose. */ @PostLoad public void calculateAge() { age = ChronoUnit.YEARS.between( LocalDateTime.ofInstant( Instant.ofEpochMilli( dateOfBirth.getTime()), ZoneOffset.UTC), LocalDateTime.now() ); } }
/** * Gets the time gap between now and next backup time. * * @return the time gap to next backup */ private long getTimeToNextBackup() { LocalDateTime now = LocalDateTime.now(Clock.systemUTC()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm"); LocalTime backupTime = LocalTime.parse(ServerConfiguration .get(PropertyKey.MASTER_DAILY_BACKUP_TIME), formatter); LocalDateTime nextBackupTime = now.withHour(backupTime.getHour()) .withMinute(backupTime.getMinute()); if (nextBackupTime.isBefore(now)) { nextBackupTime = nextBackupTime.plusDays(1); } return ChronoUnit.MILLIS.between(now, nextBackupTime); }
private void makeSureHasTimeStamp(AbstractGCEvent<?> abstractEvent) { if (size() >= 1 && abstractEvent.getTimestamp() < 0.000001 && abstractEvent.getDatestamp() != null) { // looks like there is no timestamp set -> set one, because a lot depends on the timestamps abstractEvent.setTimestamp(ChronoUnit.MILLIS.between(getFirstDateStamp(), abstractEvent.getDatestamp()) / 1000.0); } }
@Test public void shouldDeserializeTimeMicrosToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timeMicros().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MICROS.between( LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeTimeMillisToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timeMillis().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), ChronoUnit.MILLIS.between( LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeTimestampToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timestampMillis().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MILLIS.between( LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeTimestampToInteger() { shouldDeserializeTypeCorrectly( LogicalTypes.timestampMicros().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MICROS.between( LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeDateToInteger() { shouldDeserializeTypeCorrectly( LogicalTypes.date().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), (int) ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()), Schema.OPTIONAL_INT32_SCHEMA ); }
@Test public void shouldDeserializeDateToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.date().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()), Schema.OPTIONAL_INT64_SCHEMA ); }