List of usage examples for java.time Instant plus
@Override
public Instant plus(TemporalAmount amountToAdd)
From source file:Main.java
public static void main(String[] args) { Duration d1 = Duration.ofSeconds(55); Duration d2 = Duration.ofSeconds(-17); Instant i1 = Instant.now(); Instant i4 = i1.plus(d1); Instant i5 = i1.minus(d2);/*from w w w .j a v a 2 s . c o m*/ Duration d3 = d1.plus(d2); System.out.println(d3); }
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); instant = instant.plus(Duration.ofDays(100)); System.out.println(instant);//w w w .ja v a2s . c o m }
From source file:Main.java
public static void main(String[] args) { Clock utcClock = Clock.systemUTC(); Clock defaultClock = Clock.systemDefaultZone(); Clock offsetClock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-5)); ZoneId denverTimeZone = ZoneId.of("America/Denver"); ZoneId newYorkTimeZone = ZoneId.of("America/New_York"); ZoneId chicagoTimeZone = ZoneId.of("America/Chicago"); ZoneId losAngelesTimeZone = ZoneId.of("America/Los_Angeles"); Instant instant = Instant.now(defaultClock); Instant instant2 = Instant.now(utcClock); Instant instant3 = Instant.now(offsetClock); System.out.println(instant);//from ww w.j av a 2 s . c o m System.out.println(instant2); System.out.println(instant3.plus(Duration.ofSeconds(90))); System.out.println(instant3.atZone(newYorkTimeZone)); System.out.println(instant3.atZone(chicagoTimeZone)); System.out.println(instant3.atZone(denverTimeZone)); System.out.println(instant3.atZone(losAngelesTimeZone)); }
From source file:Main.java
public static void main(String[] args) { Instant t1 = Instant.now(); Instant t2 = Instant.now().plusSeconds(12); long nanos = Duration.between(t1, t2).toNanos(); System.out.println(nanos);/*from www .j av a 2 s.co m*/ Duration gap = Duration.ofSeconds(13); // 12000000000 Instant later = t1.plus(gap); System.out.println(t1); // 2014-07-02T19:55:00.956Z System.out.println(later); // 2014-07-02T19:55:13.956Z System.out.println(ChronoUnit.MILLIS.between(t1, t2)); // 12000 }
From source file:com.orange.cepheus.cep.SubscriptionManager.java
private void periodicSubscriptionTask() { Instant now = Instant.now(); Instant nextSubscriptionTaskDate = now.plusMillis(subscriptionPeriodicity); logger.info("Launch of the periodic subscription task at {}", now.toString()); // Futures will use the current subscription list. // So that they will not add old subscriptions to a new configuration. Subscriptions subscriptions = this.subscriptions; for (EventTypeIn eventType : eventTypeIns) { SubscribeContext subscribeContext = null; for (Provider provider : eventType.getProviders()) { boolean deadlineIsPassed = false; Instant subscriptionDate = provider.getSubscriptionDate(); if (subscriptionDate != null) { Instant subscriptionEndDate = subscriptionDate.plus(Duration.parse(subscriptionDuration)); // check if deadline is passed if (nextSubscriptionTaskDate.compareTo(subscriptionEndDate) >= 0) { deadlineIsPassed = true; String subscriptionId = provider.getSubscriptionId(); // if delay is passed then clear the subscription info in provider et suppress subscription if (subscriptionId != null) { subscriptions.removeSubscription(subscriptionId); provider.setSubscriptionId(null); provider.setSubscriptionDate(null); }//ww w. j av a2 s . co m } } //Send subscription if subscription is a new subscription or we do not receive a response (subscriptionDate is null) //Send subscription if deadline is passed if ((subscriptionDate == null) || deadlineIsPassed) { // lazy build body request only when the first request requires it if (subscribeContext == null) { subscribeContext = buildSubscribeContext(eventType); } subscribeProvider(provider, subscribeContext, subscriptions); } } } }
From source file:org.gameontext.map.auth.PlayerClient.java
/** * Obtain a JWT for the player id that can be used to invoke player REST services. * * We can create this, because we have access to the private certificate * required to sign such a JWT./* w w w . j a va2 s . com*/ * * @param playerId The id to build the JWT for * @return The JWT as a string. * @throws IOException */ private String buildClientJwtForId(String playerId) throws IOException { // grab the key if needed if (signingKey == null) getKeyStoreInfo(); Claims onwardsClaims = Jwts.claims(); // Set the subject using the "id" field from our claims map. onwardsClaims.setSubject(playerId); // We'll use this claim to know this is a user token onwardsClaims.setAudience("client"); // we set creation time to 24hrs ago, to avoid timezone issues // client JWT has 24 hrs validity from now. Instant timePoint = Instant.now(); onwardsClaims.setIssuedAt(Date.from(timePoint.minus(hours24))); onwardsClaims.setExpiration(Date.from(timePoint.plus(hours24))); // finally build the new jwt, using the claims we just built, signing it // with our signing key, and adding a key hint as kid to the encryption // header, which is optional, but can be used by the receivers of the // jwt to know which key they should verifiy it with. String newJwt = Jwts.builder().setHeaderParam("kid", "playerssl").setClaims(onwardsClaims) .signWith(SignatureAlgorithm.RS256, signingKey).compact(); return newJwt; }
From source file:ddf.security.samlp.impl.SamlValidator.java
protected void checkTimestamp() throws ValidationException { DateTime issueInstant = getIssueInstant(); if (issueInstant == null) { throw new ValidationException("Issue Instant cannot be null!"); }/* w w w . j ava2 s .co m*/ Instant instant = Instant.ofEpochMilli(issueInstant.getMillis()); Instant now = Instant.now(); if (instant.minus(builder.clockSkew).isAfter(now)) { throw new ValidationException("Issue Instant cannot be in the future"); } if (instant.plus(builder.clockSkew).isBefore(now.minus(builder.timeout))) { throw new ValidationException("Issue Instant was outside valid time range"); } }
From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java
@VisibleForTesting String getCronOrDelete() {// w w w . j a v a 2 s. co m if (!getTempTimestampFilePath().toFile().exists()) { // Create temp file and add timestamp Instant instant = Instant.now(); if (!createTempFile(instant)) { return null; } return cronCalculator(instant); } else { // Read timestamp Instant firstInstall = installationDate(); if (firstInstall == null) { return null; } if (Instant.now().isAfter(firstInstall.plus(Duration.ofDays(3)).minus(Duration.ofMinutes(30)))) { // Timestamp expired removeDefaultUsers(); return null; } return cronCalculator(firstInstall); } }
From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java
private String cronCalculator(Instant firstInstall) { Instant threeDayTimestamp = firstInstall.plus(Duration.ofDays(3).minus(Duration.ofMinutes(30))); LocalDateTime localDateTime = LocalDateTime.ofInstant(threeDayTimestamp, ZoneId.systemDefault()); return String.format("%d+%d+%d+%d+%d+?+%d", localDateTime.getSecond(), localDateTime.getMinute(), localDateTime.getHour(), localDateTime.getDayOfMonth(), localDateTime.getMonthValue(), localDateTime.getYear());//from www . j a v a 2s.c o m }
From source file:org.springframework.core.io.buffer.LeakAwareDataBufferFactory.java
/** * Checks whether all of the data buffers allocated by this factory have also been released. * If not, then an {@link AssertionError} is thrown. Typically used from a JUnit {@link After} * method./*from www. ja v a 2s . co m*/ */ public void checkForLeaks() { Instant start = Instant.now(); while (true) { if (this.created.stream().noneMatch(LeakAwareDataBuffer::isAllocated)) { return; } if (Instant.now().isBefore(start.plus(Duration.ofSeconds(5)))) { try { Thread.sleep(50); } catch (InterruptedException ex) { // ignore } continue; } List<AssertionError> errors = this.created.stream().filter(LeakAwareDataBuffer::isAllocated) .map(LeakAwareDataBuffer::leakError).collect(Collectors.toList()); errors.forEach(it -> logger.error("Leaked error: ", it)); throw new AssertionError(errors.size() + " buffer leaks detected (see logs above)"); } }