private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Instant targetDate) { // FIXME shouldn't this be the first analysis after targetDate? Duration bestDuration = null; SnapshotDto nearest = null; for (SnapshotDto snapshot : snapshots) { Instant createdAt = Instant.ofEpochMilli(snapshot.getCreatedAt()); Duration duration = Duration.between(targetDate, createdAt).abs(); if (bestDuration == null || duration.compareTo(bestDuration) <= 0) { bestDuration = duration; nearest = snapshot; } } return nearest; }
/** * Supports the unary plus operator; equivalent to calling the {@link Duration#abs()} method. * * @param self a Duration * @return a Duration * @since 2.5.0 */ public static Duration positive(final Duration self) { return self.abs(); }
public Builder setTemporalValidationTolerance(Duration temporalValidationTolerance) { this.temporalValidationTolerance = temporalValidationTolerance == null ? Duration.ZERO : temporalValidationTolerance.abs(); return this; }
private static String makeMessage(final String action, final Duration period) { String unit = "ms"; long amount = period.abs().toMillis(); if (amount % 1000 == 0) { amount /= 1000; unit = amount == 1 ? "second" : "seconds"; } return String.format("%s expired after %s %s", action != null ? action : DEFAULT_MESSAGE, amount, unit); }
private void sleepBeforeNextCall() throws InterruptedException { if (lastSuccessfulCall == null) { return; } long timeSinceLastCall = Duration.between(lastSuccessfulCall, Instant.now()).abs().toMillis(); if (timeSinceLastCall < idleMillisBetweenCalls) { Thread.sleep(idleMillisBetweenCalls - timeSinceLastCall); } } }
public static long timeDifference(Instant t1, Instant t2) { return Duration.between(t1, t2).abs().toMillis(); }
private void sleepBeforeNextCall() throws InterruptedException { if (lastSuccessfulCall == null) { return; } long timeSinceLastCall = Duration.between(lastSuccessfulCall, Instant.now()).abs().toMillis(); if (timeSinceLastCall < idleMillisBetweenCalls) { Thread.sleep(idleMillisBetweenCalls - timeSinceLastCall); } } }
private void sleepBeforeNextCall() throws InterruptedException { if (lastSuccessfulCall == null) { return; } long timeSinceLastCall = Duration.between(lastSuccessfulCall, Instant.now()).abs().toMillis(); if (timeSinceLastCall < idleMillisBetweenCalls) { Thread.sleep(idleMillisBetweenCalls - timeSinceLastCall); } } }
@Override protected boolean matchesSafely(Duration item, Description mismatchDescription) { Duration difference = item.minus(target).abs(); mismatchDescription.appendValue(item) .appendText(" which is ") .appendValue(difference) .appendText(" from ") .appendValue(target); return difference.compareTo(margin) <= 0; // difference <= margin }
private int figureNextDayInterval( final Instant passwordExpirationTime ) { final long maxSecondsAfterExpiration = TimeDuration.DAY.as( TimeDuration.Unit.SECONDS ); int nextDayInterval = -1; for ( final int configuredDayInterval : settings.getNotificationIntervals() ) { final Instant futureConfiguredDayInterval = Instant.now().plus( configuredDayInterval, ChronoUnit.DAYS ); final long secondsUntilConfiguredInterval = Duration.between( Instant.now(), futureConfiguredDayInterval ).abs().getSeconds(); final long secondsUntilPasswordExpiration = Duration.between( Instant.now(), passwordExpirationTime ).abs().getSeconds(); if ( secondsUntilPasswordExpiration < secondsUntilConfiguredInterval ) { final long secondsBetweenIntervalAndExpiration = Duration.between( futureConfiguredDayInterval, passwordExpirationTime ).abs().getSeconds(); if ( secondsBetweenIntervalAndExpiration < maxSecondsAfterExpiration ) { nextDayInterval = configuredDayInterval; } } } return nextDayInterval; }
@Override public HibernateValidatorConfiguration temporalValidationTolerance(Duration temporalValidationTolerance) { Contracts.assertNotNull( temporalValidationTolerance, MESSAGES.parameterMustNotBeNull( "temporalValidationTolerance" ) ); this.temporalValidationTolerance = temporalValidationTolerance.abs(); return this; }
public Duration getRemainingLockDuration() { return Duration.between(startedAt, clock.instant()).minus(heartbeatDuration).abs(); }
private Duration durationBehind(final int currentPos) { if (currentPos == -1 && eventQueue.size() > 0) { return Duration.between( getLast(eventQueue).getHeader().getAsInstant("synapse_msg_arrival_ts"), eventQueue.get(eventQueue.size()-1).getHeader().getAsInstant("synapse_msg_arrival_ts")) .abs(); } else if (currentPos >= 0 && currentPos <= eventQueue.size()) { return Duration.between( getLast(eventQueue).getHeader().getAsInstant("synapse_msg_arrival_ts"), eventQueue.get(currentPos).getHeader().getAsInstant("synapse_msg_arrival_ts")) .abs(); } else { return ZERO; } }
final Instant end = start.plus(duration.abs()); while (Instant.now().isBefore(end)) { try {
Duration absDuration = duration.abs(); int days = 0; if (absDuration.getSeconds() != 0) {
for (Entry<String, LocalDateTime> entry : cache.entrySet()) { String propsKey = entry.getKey() + market + "_sell_only_mode"; long age = Duration.between(now, entry.getValue()).abs().toDays(); if (age <= days) { if (props != null && !props.containsKey(propsKey)) {
Duration absDuration = duration.abs(); int days = 0; if (absDuration.getSeconds() != 0) {
private Instant figureNextJobExecutionTime() throws PwmUnrecoverableException { final PwNotifyStoredJobState pwNotifyStoredJobState = storageService.readStoredJobState(); if ( pwNotifyStoredJobState != null ) { // never run, or last job not successful. if ( pwNotifyStoredJobState.getLastCompletion() == null || pwNotifyStoredJobState.getLastError() != null ) { return Instant.now().plus( 1, ChronoUnit.MINUTES ); } // more than 24hr ago. final long maxSeconds = settings.getMaximumSkipWindow().as( TimeDuration.Unit.SECONDS ); if ( Duration.between( Instant.now(), pwNotifyStoredJobState.getLastCompletion() ).abs().getSeconds() > maxSeconds ) { return Instant.now(); } } final Instant nextZuluZeroTime = JavaHelper.nextZuluZeroTime(); final Instant adjustedNextZuluZeroTime = nextZuluZeroTime.plus( settings.getZuluOffset().as( TimeDuration.Unit.SECONDS ), ChronoUnit.SECONDS ); final Instant previousAdjustedZuluZeroTime = adjustedNextZuluZeroTime.minus( 1, ChronoUnit.DAYS ); if ( previousAdjustedZuluZeroTime.isAfter( Instant.now() ) ) { return previousAdjustedZuluZeroTime; } return adjustedNextZuluZeroTime; }
private Duration getTemporalValidationTolerance(ConfigurationState configurationState, Map<String, String> properties) { if ( configurationState instanceof ConfigurationImpl ) { ConfigurationImpl hibernateSpecificConfig = (ConfigurationImpl) configurationState; if ( hibernateSpecificConfig.getTemporalValidationTolerance() != null ) { LOG.logTemporalValidationTolerance( hibernateSpecificConfig.getTemporalValidationTolerance() ); return hibernateSpecificConfig.getTemporalValidationTolerance(); } } String temporalValidationToleranceProperty = properties.get( HibernateValidatorConfiguration.TEMPORAL_VALIDATION_TOLERANCE ); if ( temporalValidationToleranceProperty != null ) { try { Duration tolerance = Duration.ofMillis( Long.parseLong( temporalValidationToleranceProperty ) ).abs(); LOG.logTemporalValidationTolerance( tolerance ); return tolerance; } catch (Exception e) { throw LOG.getUnableToParseTemporalValidationToleranceException( temporalValidationToleranceProperty, e ); } } return Duration.ZERO; }