List of usage examples for java.time ZonedDateTime plusDays
public ZonedDateTime plusDays(long days)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.plusDays(1234); System.out.println(n);/*from ww w .ja v a2s.c o m*/ }
From source file:io.stallion.services.SecureTempTokens.java
public TempToken getOrCreate(String key) { ZonedDateTime expires = DateUtils.utcNow(); expires = expires.plusDays(7); return getOrCreate(key, expires); }
From source file:com.omertron.slackbot.functions.scheduler.AbstractBotTask.java
/** * Calculate the time between "now" and the execution time. * * @param targetHour// w w w.ja v a 2 s . c o m * @param targetMin * @param targetSec * @return */ private long computeNextDelay(int targetHour, int targetMin, int targetSec) { ZonedDateTime zonedNow = localeDateTime(); ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec) .withNano(0); if (zonedNow.compareTo(zonedNextTarget) >= 0) { zonedNextTarget = zonedNextTarget.plusDays(1); } Duration duration = Duration.between(zonedNow, zonedNextTarget); // If we are scheduled within the next minute, then skip a day as we probably just ran fast if (duration.getSeconds() <= 60l) { zonedNextTarget = zonedNextTarget.plusDays(1); duration = Duration.between(zonedNow, zonedNextTarget); } return duration.getSeconds(); }
From source file:alfio.manager.TicketReservationManager.java
public static ZonedDateTime getOfflinePaymentDeadline(Event event, ConfigurationManager configurationManager) { ZonedDateTime now = ZonedDateTime.now(event.getZoneId()); int waitingPeriod = getOfflinePaymentWaitingPeriod(event, configurationManager); if (waitingPeriod == 0) { log.warn(// w ww. j a v a 2 s. c o m "accepting offline payments the same day is a very bad practice and should be avoided. Please set cash payment as payment method next time"); //if today is the event start date, then we add a couple of hours. //TODO Maybe should we avoid this wrong behavior upfront, in the admin area? return now.plusHours(2); } return now.plusDays(waitingPeriod).truncatedTo(ChronoUnit.HALF_DAYS); }
From source file:nu.yona.server.analysis.service.ActivityServiceTest.java
@Test public void getUserDayActivityOverviews_activityPresent_resultsWithActivity() { ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone)); ZonedDateTime yesterday = today.minusDays(1); // gambling goal was created 2 weeks ago, see above // mock some activity on yesterday 20:58-21:00 DayActivity yesterdayRecordedActivity = DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, yesterday.toLocalDate()); Activity recordedActivity = Activity.createInstance(userAnonZone, yesterday.plusHours(20).plusMinutes(58).toLocalDateTime(), yesterday.plusHours(21).plusMinutes(00).toLocalDateTime(), Optional.empty()); yesterdayRecordedActivity.addActivity(recordedActivity); Set<UUID> relevantGoalIds = userAnonEntity.getGoals().stream().map(Goal::getId).collect(Collectors.toSet()); when(mockDayActivityRepository.findAll(userAnonId, relevantGoalIds, today.minusDays(2).toLocalDate(), today.plusDays(1).toLocalDate())).thenReturn(Arrays.asList(yesterdayRecordedActivity)); Page<DayActivityOverviewDto<DayActivityDto>> dayOverviews = service.getUserDayActivityOverviews(userId, new PageRequest(0, 3)); // assert that the right retrieve from database was done verify(mockDayActivityRepository, times(1)).findAll(userAnonId, relevantGoalIds, today.minusDays(2).toLocalDate(), today.plusDays(1).toLocalDate()); // because the gambling goal was added with creation date two weeks ago, there are multiple days, equal to the limit of // our page request = 3 assertThat(dayOverviews.getNumberOfElements(), equalTo(3)); // get the current day (first item) DayActivityOverviewDto<DayActivityDto> dayOverview = dayOverviews.getContent().get(0); assertThat(dayOverview.getDayActivities().size(), equalTo(userAnonEntity.getGoals().size())); DayActivityDto dayActivityForGambling = dayOverview.getDayActivities().stream() .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get(); assertThat(dayActivityForGambling.getStartTime(), equalTo(today)); assertThat(dayActivityForGambling.getTotalActivityDurationMinutes().get(), equalTo(0)); assertThat(dayActivityForGambling.getTotalMinutesBeyondGoal(), equalTo(0)); // get yesterday, with recorded activity dayOverview = dayOverviews.getContent().get(1); assertThat(dayOverview.getDayActivities().size(), equalTo(1)); dayActivityForGambling = dayOverview.getDayActivities().stream() .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get(); assertThat(dayActivityForGambling.getStartTime(), equalTo(yesterday)); assertThat(dayActivityForGambling.getTotalActivityDurationMinutes().get(), equalTo(2)); assertThat(dayActivityForGambling.getTotalMinutesBeyondGoal(), equalTo(2)); }
From source file:org.apache.geode.management.internal.cli.commands.ExportLogsDUnitTest.java
@Test public void startAndEndDateCanIncludeLogs() throws Exception { ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault()); ZonedDateTime yesterday = now.minusDays(1); ZonedDateTime tomorrow = now.plusDays(1); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT); CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs"); commandStringBuilder.addOption("start-time", dateTimeFormatter.format(yesterday)); commandStringBuilder.addOption("end-time", dateTimeFormatter.format(tomorrow)); commandStringBuilder.addOption("log-level", "debug"); gfshConnector.executeAndVerifyCommand(commandStringBuilder.toString()); Set<String> acceptedLogLevels = Stream.of("info", "error", "debug").collect(toSet()); verifyZipFileContents(acceptedLogLevels); }
From source file:sg.ncl.MainController.java
private List<String> getDates(String start, String end, DateTimeFormatter formatter) { List<String> dates = new ArrayList<>(); ZonedDateTime currentZonedDateTime = convertToZonedDateTime(start); ZonedDateTime endZoneDateTime = convertToZonedDateTime(end); while (currentZonedDateTime.isBefore(endZoneDateTime)) { String date = currentZonedDateTime.format(formatter); dates.add(date);/*w ww .ja v a 2 s . c om*/ currentZonedDateTime = currentZonedDateTime.plusDays(1); } dates.add(currentZonedDateTime.format(formatter)); return dates; }