Example usage for java.time Instant minus

List of usage examples for java.time Instant minus

Introduction

In this page you can find the example usage for java.time Instant minus.

Prototype

@Override
public Instant minus(TemporalAmount amountToSubtract) 

Source Link

Document

Returns a copy of this instant with the specified amount subtracted.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    instant = instant.minus(Duration.ofDays(100));
    System.out.println(instant);/*from w ww . j a  va 2 s .co m*/

}

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);//from   w w w.  j  ava  2  s.c  om
    Instant i5 = i1.minus(d2);

    Duration d3 = d1.plus(d2);
    System.out.println(d3);
}

From source file:Main.java

public static void main(String[] args) {

    // same time in millis
    Instant now = Instant.ofEpochMilli(1262347200000l);

    // native plusSeconds() method to add 10 seconds
    Instant nowPlusTenSeconds = now.plusSeconds(10);

    // no native support for units like days.
    Instant nowPlusTwoDays = now.plus(2, ChronoUnit.DAYS);
    Instant nowMinusTwoDays = now.minus(Duration.ofDays(2));

    System.out.println(nowPlusTenSeconds);
    System.out.println(nowPlusTwoDays);
    System.out.println(nowMinusTwoDays);
}

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 v a2 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:org.ulyssis.ipp.ui.widgets.TeamPanel.java

private void updateCharts() {
    Instant now = Instant.now();
    Instant anHourAgo = now.minus(Duration.ofHours(1L));
    try (Connection connection = Database.createConnection(EnumSet.of(Database.ConnectionFlags.READ_ONLY))) {
        List<Event> events = Event.loadFrom(connection, anHourAgo);
        if (events.size() == 0) {
            LOG.warn("No events");
            return;
        }/*from w  ww  .j a  v  a2 s  .c  o  m*/
        Snapshot snapshot = Snapshot.loadForEvent(connection, events.get(0)).get(); // If it's not there, this is a fatal error
        List<Optional<Instant>> eventTimes = new ArrayList<>();
        List<List<TagSeenEvent>> eventLists = new ArrayList<>();
        for (int i = 0; i < config.getNbReaders(); i++) {
            eventTimes.add(Optional.empty());
            eventLists.add(new ArrayList<>());
        }
        for (int i = 1; i < events.size(); ++i) {
            Event event = events.get(i);
            snapshot = event.apply(snapshot);
            if (event instanceof TagSeenEvent && !event.isRemoved()) { // TODO(Roel): Well, we can't actually remove it, right?
                final TagSeenEvent tagSeenEvent = (TagSeenEvent) event;
                Optional<Integer> teamNb = snapshot.getTeamTagMap().tagToTeam(tagSeenEvent.getTag());
                if (teamNb.isPresent() && teamNb.get().equals(team.getTeamNb())) {
                    // TODO(Roel): This hack is kind of dirty. In fact, all of this
                    //             code is kind of dirty.
                    if (eventTimes.get(tagSeenEvent.getReaderId()).isPresent()) {
                        if (Duration.between(eventTimes.get(tagSeenEvent.getReaderId()).get(), event.getTime())
                                .toMillis() <= 30_000) {
                            continue;
                        }
                    }
                    eventTimes.get(tagSeenEvent.getReaderId()).ifPresent(lastTime -> {
                        try {
                            eventLists.get(tagSeenEvent.getReaderId()).add(tagSeenEvent);
                        } catch (Exception e) {
                            LOG.error("Exception", e);
                        }
                    });
                    eventTimes.set(tagSeenEvent.getReaderId(), Optional.of(event.getTime()));
                }
            }
        }
        for (int i = 0; i < config.getNbReaders(); i++) {
            List<TagSeenEvent> eventList = eventLists.get(i);
            List<TagSeenEvent> shortenedEventList = new ArrayList<>();
            if (eventList.size() > 40) {
                for (int j = eventList.size() - 40; j < eventList.size(); j++) {
                    shortenedEventList.add(eventList.get(j));
                }
            } else {
                shortenedEventList = eventList;
            }
            itemModels.get(i).setEvents(anHourAgo, shortenedEventList);
        }
    } catch (SQLException e) {
        LOG.error("Couldn't fetch events", e);
    } catch (IOException e) {
        LOG.error("Error processing events", e);
    }
}

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!");
    }//from  w  ww. j a va  2s  .  c om

    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");
    }

}