Example usage for java.time Instant plusMillis

List of usage examples for java.time Instant plusMillis

Introduction

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

Prototype

public Instant plusMillis(long millisToAdd) 

Source Link

Document

Returns a copy of this instant with the specified duration in milliseconds added.

Usage

From source file:Main.java

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

}

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);
                    }/*from  w w w  . ja  v a  2 s .c  o  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.ng200.openolympus.controller.api.ContestTimerController.java

@RequestMapping("/api/contestTimeRemaining/{contest}")
public @ResponseBody Map<String, String> getTimeRemaining(@PathVariable("contest") final Contest contest,
        final Principal principal) {
    Assertions.resourceExists(contest);//from   ww w  . j a v  a2 s .c  om

    Instant end = contest.getStartTime().toInstant();
    final boolean isInProcess = contest.getStartTime().before(java.util.Date.from(Instant.now()));
    if (isInProcess) {
        if (this.contestSecurityService.isSuperuser(principal)) {
            end = this.contestService.getContestEndIncludingAllTimeExtensions(contest);
        } else if (principal != null) {
            final User user = this.userRepository.findByUsername(principal.getName());
            if (user != null) {
                end = end.plusMillis(contest.getDuration())
                        .plusMillis(this.contestService.getTimeExtensions(contest, user));
            }
        }
    }
    if (principal != null) {
        this.contestService.getTimeExtensions(contest, this.userRepository.findByUsername(principal.getName()));
    }
    final Instant cur = Instant.now();
    if (end.isBefore(cur)) {
        return new HashMap<String, String>() {
            /**
             *
             */
            private static final long serialVersionUID = 5419629757758058933L;

            {
                this.put("timer", "00:00:00");
                this.put("status", "ended");
            }
        };
    }
    final Duration duration = Duration.between(cur, end);
    final DecimalFormat format = new DecimalFormat("00");
    final long hours = duration.toHours();
    final long minutes = duration.minusHours(hours).toMinutes();
    final long seconds = duration.minusHours(hours).minusMinutes(minutes).getSeconds();
    return new HashMap<String, String>() {
        /**
         *
         */
        private static final long serialVersionUID = -4698243010184691932L;

        {
            this.put("timer",
                    format.format(hours) + ":" + format.format(minutes) + ":" + format.format(seconds));

            this.put("status", isInProcess ? "inProgress" : "notStartedYet");
        }
    };
}