List of usage examples for java.time ZonedDateTime plus
@Override
public ZonedDateTime plus(TemporalAmount amountToAdd)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.plus(Period.ofYears(12)); System.out.println(n);//from www.jav a2s .com }
From source file:Main.java
public static void main(String[] args) { ZoneId usCentral = ZoneId.of("America/Chicago"); LocalDateTime ldt = LocalDateTime.of(2012, Month.MARCH, 10, 7, 30); ZonedDateTime zdt1 = ZonedDateTime.of(ldt, usCentral); Period p1 = Period.ofDays(1); ZonedDateTime zdt2 = zdt1.plus(p1); System.out.println(zdt2);//from w ww . j a v a 2 s . c o m }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime _130AMChicagoTime = ZonedDateTime.of(2014, 3, 9, 1, 30, 0, 0, ZoneId.of("America/Chicago")); System.out.println(_130AMChicagoTime.plusHours(3)); System.out.println(_130AMChicagoTime.plus(Duration.ofHours(3))); System.out.println(_130AMChicagoTime.plus(Duration.ofDays(2))); System.out.println(_130AMChicagoTime.plus(Period.ofDays(2))); }
From source file:com.querydsl.webhooks.GithubReviewWindow.java
@Bean public PullRequestHandler reviewWindowHandler(Environment environment) { Duration defaultReviewWindow = Duration.parse(environment.getRequiredProperty("duration")); //duration is the default window Map<String, ScheduledFuture<?>> asyncTasks = Maps.newConcurrentMap(); return payload -> { PullRequest pullRequest = payload.getPullRequest(); Ref head = pullRequest.getHead(); try {//from w w w . j a v a2 s .com GHRepository repository = github.getRepository(payload.getRepository().getFullName()); Collection<GHLabel> labels = repository.getIssue(pullRequest.getNumber()).getLabels(); Duration reviewTime = labels.stream().map(label -> "duration." + label.getName()) //for all duration.[label] properties .map(environment::getProperty).filter(Objects::nonNull) //look for a Duration .findFirst().map(Duration::parse).orElse(defaultReviewWindow); //if none found, use the default window ZonedDateTime creationTime = pullRequest.getCreatedAt(); ZonedDateTime windowCloseTime = creationTime.plus(reviewTime); boolean windowPassed = now().isAfter(windowCloseTime); logger.info("creationTime({}) + reviewTime({}) = windowCloseTime({}), so windowPassed = {}", creationTime, reviewTime, windowCloseTime, windowPassed); if (windowPassed) { completeAndCleanUp(asyncTasks, repository, head); } else { createPendingMessage(repository, head, reviewTime); ScheduledFuture<?> scheduledTask = taskScheduler.schedule( () -> completeAndCleanUp(asyncTasks, repository, head), Date.from(windowCloseTime.toInstant())); replaceCompletionTask(asyncTasks, scheduledTask, head); } } catch (IOException ex) { throw Throwables.propagate(ex); } }; }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void addActivity_afterConflictIntervalLastRegisteredActivity_goalConflictMessageCreated() { ZonedDateTime t1 = now(); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(createActivity(t1, t1)); ZonedDateTime t2 = t1.plus(mockYonaProperties.getAnalysisService().getConflictInterval()).plusSeconds(1); service.addActivity(userAnonEntity, createPayload(t2, t2), GoalDto.createInstance(gamblingGoal), Optional.of(lastRegisteredActivity)); verifyGoalConflictMessageCreated(gamblingGoal); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void addActivity_withinConflictIntervalLastRegisteredActivity_noGoalConflictMessagesCreated() { ZonedDateTime t1 = now(); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(createActivity(t1, t1)); ZonedDateTime t2 = t1.plus(mockYonaProperties.getAnalysisService().getConflictInterval()).minusSeconds(1); service.addActivity(userAnonEntity, createPayload(t2, t2), GoalDto.createInstance(gamblingGoal), Optional.of(lastRegisteredActivity)); verifyNoGoalConflictMessagesCreated(); }
From source file:org.edgexfoundry.scheduling.ScheduleContext.java
private ZonedDateTime initNextTime(ZonedDateTime start, ZonedDateTime now, Period period, Duration duration) { // if the start time is in the future next will just be start ZonedDateTime next = start; // if the start time is in the past, increment until we find the next time to execute // cannot call isComplete() here as it depends on nextTime if (startTime.compareTo(now) <= 0 && !schedule.getRunOnce()) { // TODO: optimize the below. consider a one-second timer case... // For example if only a single unit, e.g. only minutes, then can optimize relative to start // if there are more than one unit, then the loop may be best as it will be difficult while (next.compareTo(now) <= 0) { next = next.plus(period); next = next.plus(duration);/*from w w w .j av a 2s . c om*/ } } return next; }