Example usage for java.time Clock instant

List of usage examples for java.time Clock instant

Introduction

In this page you can find the example usage for java.time Clock instant.

Prototype

public abstract Instant instant();

Source Link

Document

Gets the current instant of the clock.

Usage

From source file:no.digipost.api.useragreements.client.response.ResponseUtils.java

public static Optional<Duration> parseDelayDurationOfRetryAfterHeader(HttpResponse response, Clock clock) {
    return getValueOfFirstHeader(response, Headers.Retry_After).map(retryAfterValue -> {
        try {/*from   w  ww  . j a v a2 s  . com*/
            long parsedSeconds = Long.parseLong(retryAfterValue);
            return Duration.ofSeconds(parsedSeconds);
        } catch (NumberFormatException secondsNotParseable) {
            try {
                Instant parsedInstant = RFC_1123_DATE_TIME.parse(retryAfterValue, Instant::from);
                return Duration.between(clock.instant(), parsedInstant);
            } catch (RuntimeException e) {
                e.addSuppressed(secondsNotParseable);
                throw e;
            }
        }
    });
}

From source file:fi.luontola.cqrshotel.reservation.events.PriceOffered.java

public boolean isStillValid(Clock clock) {
    return expires.isAfter(clock.instant());
}