List of usage examples for java.time ZonedDateTime plusHours
public ZonedDateTime plusHours(long hours)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.plusHours(1234); System.out.println(n);/* w w w . j ava 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:Main.java
public static void main(String[] argv) { LocalDateTime now = LocalDateTime.now(); ZonedDateTime zonedDateTime = ZonedDateTime.of(now, TimeZone.NEW_YORK); System.out.println("now = " + now); System.out.println("Current date and time in a particular timezone : " + zonedDateTime); now = LocalDateTime.now(TimeZone.INDIA); System.out.println("now in India = " + now); zonedDateTime = ZonedDateTime.now(); System.out.println("zonedDateTime with default(system) timezone = " + zonedDateTime); System.out.println("zonedDateTime with India timezone = " + ZonedDateTime.now(TimeZone.INDIA)); String isoFormatted = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(TimeZone.INDIA)); System.out.println("ISO Formatted = " + isoFormatted); ZonedDateTime utahMarch8thAt2AM = ZonedDateTime.of(LocalDateTime.of(2015, 3, 8, 1, 0), TimeZone.UTAH); System.out.println("utahMarch8thAt2AM = " + utahMarch8thAt2AM); System.out.println("utahMarch8thAt2AM.plusHours(1) = " + utahMarch8thAt2AM.plusHours(1)); System.out.println("utahMarch8thAt2AM.plusHours(2) = " + utahMarch8thAt2AM.plusHours(2)); }
From source file:com.github.ibm.domino.client.CalendarClientTest.java
@Test public void test1PostEvents() { System.out.println("postEvents"); DominoRestClient instance = initClient(); CalendarEventsWrapper events = new CalendarEventsWrapper(); CalendarEvent event = new CalendarEvent(); event.setSummary("This is a new event"); event.setLocation("here"); ZonedDateTime zdt = ZonedDateTime.now().plusDays(10); event.getStart().setDateTime(zdt);/* www . j av a 2 s. c o m*/ event.getEnd().setDateTime(zdt.plusHours(2)); events.getEvents().add(event); ResponseEntity<Object> response = instance.postEvent(events); assertTrue(response.getStatusCode().is2xxSuccessful()); }
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 w w . ja v a2s . c om*/ "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:nu.yona.server.analysis.service.ActivityServiceTest.java
@Test public void getUserWeekActivityOverviews_activityPresent_resultsWithActivity() { ZonedDateTime today = getDayStartTime(ZonedDateTime.now(userAnonZone)); // gambling goal was created 2 weeks ago, see above // mock some activity in previous week on Saturday 19:10-19:55 WeekActivity previousWeekRecordedActivity = WeekActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today.minusWeeks(1)).toLocalDate()); ZonedDateTime saturdayStartOfDay = getWeekStartTime(today).minusDays(1); DayActivity previousWeekSaturdayRecordedActivity = DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, saturdayStartOfDay.toLocalDate()); Activity recordedActivity = Activity.createInstance(userAnonZone, saturdayStartOfDay.plusHours(19).plusMinutes(10).toLocalDateTime(), saturdayStartOfDay.plusHours(19).plusMinutes(55).toLocalDateTime(), Optional.empty()); previousWeekSaturdayRecordedActivity.addActivity(recordedActivity); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(7).toLocalDate())); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(6).toLocalDate())); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(5).toLocalDate())); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(4).toLocalDate())); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(3).toLocalDate())); previousWeekRecordedActivity.addDayActivity(DayActivity.createInstance(userAnonEntity, gamblingGoal, userAnonZone, getWeekStartTime(today).minusDays(2).toLocalDate())); previousWeekRecordedActivity.addDayActivity(previousWeekSaturdayRecordedActivity); when(mockWeekActivityRepository.findAll(userAnonId, getWeekStartTime(today.minusWeeks(4)).toLocalDate(), getWeekStartTime(today).plusWeeks(1).toLocalDate())) .thenReturn(new HashSet<>(Arrays.asList(previousWeekRecordedActivity))); Page<WeekActivityOverviewDto> weekOverviews = service.getUserWeekActivityOverviews(userId, new PageRequest(0, 5)); // assert that the right retrieve from database was done verify(mockWeekActivityRepository, times(1)).findAll(userAnonId, getWeekStartTime(today.minusWeeks(4)).toLocalDate(), getWeekStartTime(today).plusWeeks(1).toLocalDate()); // because the gambling goal was added with creation date two weeks ago, there are multiple weeks assertThat(weekOverviews.getNumberOfElements(), equalTo(3)); // get the current week (first item) WeekActivityOverviewDto weekOverview = weekOverviews.getContent().get(0); assertThat(weekOverview.getWeekActivities().size(), equalTo(userAnonEntity.getGoals().size())); WeekActivityDto weekActivityForGambling = weekOverview.getWeekActivities().stream() .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get(); assertThat(weekActivityForGambling.getStartTime(), equalTo(getWeekStartTime(today))); // TODO: mock day activity in this week? // int thisWeekNumberOfWeekDaysPast = today.getDayOfWeek() == DayOfWeek.SUNDAY ? 0 : today.getDayOfWeek().getValue(); // assertThat(weekActivityForGambling.getDayActivities().size(), equalTo(1 + thisWeekNumberOfWeekDaysPast)); //// always contains Sunday because it is the first day of the week // assertThat(weekActivityForGambling.getDayActivities(), hasKey(DayOfWeek.SUNDAY)); // get the previous week, with recorded activity weekOverview = weekOverviews.getContent().get(1); assertThat(weekOverview.getWeekActivities().size(), equalTo(1)); weekActivityForGambling = weekOverview.getWeekActivities().stream() .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get(); assertThat(weekActivityForGambling.getStartTime(), equalTo(getWeekStartTime(today.minusWeeks(1)))); assertThat(weekActivityForGambling.getDayActivities().size(), equalTo(7)); DayActivityDto previousWeekSaturdayActivity = weekActivityForGambling.getDayActivities() .get(DayOfWeek.SATURDAY); assertThat(previousWeekSaturdayActivity.getTotalActivityDurationMinutes().get(), equalTo(45)); assertThat(previousWeekSaturdayActivity.getTotalMinutesBeyondGoal(), equalTo(45)); DayActivityDto previousWeekFridayActivity = weekActivityForGambling.getDayActivities() .get(DayOfWeek.FRIDAY); assertThat(previousWeekFridayActivity.getTotalActivityDurationMinutes().get(), equalTo(0)); // get the week the gambling goal was created weekOverview = weekOverviews.getContent().get(2); assertThat(weekOverview.getWeekActivities().size(), equalTo(1)); weekActivityForGambling = weekOverview.getWeekActivities().stream() .filter(a -> a.getGoalId().equals(gamblingGoal.getId())).findAny().get(); assertThat(weekActivityForGambling.getStartTime(), equalTo(getWeekStartTime(today.minusWeeks(2)))); // TODO: mock day activity in this week? // int expectedNumberOfWeekDaysRecorded = gamblingGoal.getCreationTime().getDayOfWeek() == DayOfWeek.SUNDAY ? 7 // : 7 - gamblingGoal.getCreationTime().getDayOfWeek().getValue(); // assertThat(weekActivityForGambling.getDayActivities().size(), equalTo(expectedNumberOfWeekDaysRecorded)); //// always contains Saturday because it is the last day of the week // assertThat(weekActivityForGambling.getDayActivities(), hasKey(DayOfWeek.SATURDAY)); }