List of usage examples for java.time ZonedDateTime toLocalDate
@Override
public LocalDate toLocalDate()
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); LocalDate l = dateTime.toLocalDate(); System.out.println(l);/*from ww w . j ava2 s .c om*/ }
From source file:nu.yona.server.analysis.service.InactivityManagementService.java
private WeekActivity createWeekInactivity(UUID userAnonymizedId, UUID goalId, ZonedDateTime weekStartTime) { return createInactivity(userAnonymizedId, goalId, () -> weekActivityRepository.findOne(userAnonymizedId, weekStartTime.toLocalDate(), goalId), (ua, g) -> WeekActivity.createInstance(ua, g, weekStartTime.getZone(), weekStartTime.toLocalDate()), wa -> wa.getGoal().addWeekActivity(wa)); }
From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java
private void check(DateQueries dq, String key, ZonedDateTime now) { Assert.assertEquals(now, dq.findByKey(key).value); Assert.assertEquals(now, dq.findDateByKey(key)); Assert.assertEquals(now.toLocalDate(), dq.findByKey(key).valueLocalDate); Assert.assertEquals(now.toLocalDateTime(), dq.findByKey(key).valueLocalDateTime); }
From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java
@Test public void dateQueriesTest() { QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource)); qf.addColumnMapperFactory(new ZonedDateTimeMapper.Factory()); qf.addParameterConverters(new ZonedDateTimeMapper.Converter()); qf.addColumnMapperFactory(new LocalDateMapper.Factory()); qf.addParameterConverters(new LocalDateMapper.Converter()); qf.addColumnMapperFactory(new LocalDateTimeMapper.Factory()); qf.addParameterConverters(new LocalDateTimeMapper.Converter()); qf.addColumnMapperFactory(new InstantMapper.Factory()); qf.addParameterConverters(new InstantMapper.Converter()); DateQueries dq = qf.from(DateQueries.class); dq.createTable();//from w w w. j a v a 2 s. c o m ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); dq.insertValue("KEY", now); check(dq, "KEY", now); dq.insertValue("KEY2", now.toLocalDate()); check(dq, "KEY2", now.toLocalDate()); dq.insertValue("KEY3", now.toLocalDateTime()); check(dq, "KEY3", now); Instant iNow = Instant.now(); dq.insertValue("KEY4", iNow); Assert.assertEquals(iNow, dq.findInstantByKey("KEY4")); Assert.assertEquals(iNow, dq.findConfInstantByKey("KEY4").value); }
From source file:nu.yona.server.analysis.service.ActivityUpdateService.java
private DayActivity createNewDayActivity(UserAnonymized userAnonymizedEntity, ActivityPayload payload, Goal matchingGoal) {//ww w.ja va 2 s . co m DayActivity dayActivity = DayActivity.createInstance(userAnonymizedEntity, matchingGoal, payload.startTime.getZone(), TimeUtil.getStartOfDay(payload.userAnonymized.getTimeZone(), payload.startTime).toLocalDate()); dayActivityRepository.save(dayActivity); ZonedDateTime startOfWeek = TimeUtil.getStartOfWeek(payload.userAnonymized.getTimeZone(), payload.startTime); WeekActivity weekActivity = weekActivityRepository.findOne(payload.userAnonymized.getId(), matchingGoal.getId(), startOfWeek.toLocalDate()); if (weekActivity == null) { weekActivity = WeekActivity.createInstance(userAnonymizedEntity, matchingGoal, startOfWeek.getZone(), startOfWeek.toLocalDate()); matchingGoal.addWeekActivity(weekActivity); } weekActivity.addDayActivity(dayActivity); return dayActivity; }
From source file:alfio.manager.TicketReservationManager.java
public static int getOfflinePaymentWaitingPeriod(Event event, ConfigurationManager configurationManager) { ZonedDateTime now = ZonedDateTime.now(event.getZoneId()); ZonedDateTime eventBegin = event.getBegin(); int daysToBegin = (int) ChronoUnit.DAYS.between(now.toLocalDate(), eventBegin.toLocalDate()); if (daysToBegin < 0) { throw new OfflinePaymentException("Cannot confirm an offline reservation after event start"); }/*from w w w . ja va 2 s . c o m*/ int waitingPeriod = configurationManager.getIntConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), OFFLINE_PAYMENT_DAYS), 5); return Math.min(daysToBegin, waitingPeriod); }
From source file:nu.yona.server.analysis.service.AnalysisEngineServiceTest.java
@Test public void analyze_appActivityPreviousDayPrecedingCachedDayActivity_addActivity() { ZonedDateTime now = now();//from www . j a v a2s.c o m ZonedDateTime yesterdayNoon = now.minusDays(1).withHour(12).withMinute(0).withSecond(0); mockExistingActivity(gamblingGoal, now); ZonedDateTime startTime = yesterdayNoon; ZonedDateTime endTime = yesterdayNoon.plusMinutes(10); service.analyze(userAnonId, deviceAnonId, createSingleAppActivity("Poker App", startTime, endTime)); // Verify that a database lookup was done for yesterday verify(mockDayActivityRepository).findOne(userAnonId, yesterdayNoon.toLocalDate(), gamblingGoal.getId()); verify(mockActivityUpdater).addActivity(any(), any(), eq(GoalDto.createInstance(gamblingGoal)), any()); verify(mockActivityUpdater, never()).updateTimeExistingActivity(any(), any()); verify(mockActivityUpdater, never()).updateTimeLastActivity(any(), any(), any()); }
From source file:nu.yona.server.analysis.service.AnalysisEngineServiceTest.java
@Test public void analyze_appActivityCompletelyPrecedingLastCachedActivityOverlappingExistingActivity_updateTimeExistingActivity() { ZonedDateTime now = now(); JUnitUtil.skipBefore("Skip shortly after midnight", now, 0, 30); ZonedDateTime existingActivityTimeStartTime = now.minusMinutes(20); ZonedDateTime existingActivityTimeEndTime = existingActivityTimeStartTime.plusMinutes(10); Activity existingActivityOne = createActivity(existingActivityTimeStartTime, existingActivityTimeEndTime, "Poker App"); Activity existingActivityTwo = createActivity(now, now, "Poker App"); mockExistingActivities(gamblingGoal, existingActivityOne, existingActivityTwo); when(mockActivityRepository.findOverlappingOfSameApp(any(DayActivity.class), any(UUID.class), any(UUID.class), any(String.class), any(LocalDateTime.class), any(LocalDateTime.class))) .thenAnswer(new Answer<List<Activity>>() { @Override public List<Activity> answer(InvocationOnMock invocation) throws Throwable { return Arrays.asList(existingActivityOne); }/*from w ww. jav a2 s . c om*/ }); // Test an activity ZonedDateTime startTime = existingActivityTimeStartTime.plusMinutes(5); ZonedDateTime endTime = startTime.plusMinutes(7); service.analyze(userAnonId, deviceAnonId, createSingleAppActivity("Poker App", startTime, endTime)); // Verify that a database lookup was done finding the existing DayActivity to update verify(mockDayActivityRepository).findOne(userAnonId, now.toLocalDate(), gamblingGoal.getId()); verify(mockActivityUpdater).updateTimeExistingActivity(any(), any()); verify(mockActivityUpdater, never()).addActivity(any(), any(), any(), any()); verify(mockActivityUpdater, never()).updateTimeLastActivity(any(), any(), any()); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void addActivity_appActivityOnNewDay_newDayActivityButNoGoalConflictMessageCreated() { ZonedDateTime today = now().truncatedTo(ChronoUnit.DAYS); // mock earlier activity at yesterday 23:59:58, // add new activity at today 00:00:01 ZonedDateTime existingActivityTime = today.minusDays(1).withHour(23).withMinute(59).withSecond(58); DayActivity existingDayActivity = mockExistingActivity(gamblingGoal, existingActivityTime); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingDayActivity.getActivities().get(0)); ZonedDateTime startTime = today.withHour(0).withMinute(0).withSecond(1); ZonedDateTime endTime = today.withHour(0).withMinute(10); service.addActivity(userAnonEntity, createPayload(startTime, endTime), GoalDto.createInstance(gamblingGoal), Optional.of(lastRegisteredActivity)); verifyNoGoalConflictMessagesCreated(); // Verify there are now two day activities verify(mockUserAnonymizedService, atLeastOnce()).updateUserAnonymized(userAnonEntity); List<WeekActivity> weekActivities = gamblingGoal.getWeekActivities(); assertThat("One week activity created", weekActivities.size(), equalTo(1)); List<DayActivity> dayActivities = weekActivities.get(0).getDayActivities(); assertThat("Two day activities created", dayActivities.size(), equalTo(2)); DayActivity yesterdaysDayActivity;/*from w w w . ja v a 2 s.c om*/ DayActivity todaysDayActivity; if (dayActivities.get(0).getStartDate().isBefore(dayActivities.get(1).getStartDate())) { yesterdaysDayActivity = dayActivities.get(0); todaysDayActivity = dayActivities.get(1); } else { yesterdaysDayActivity = dayActivities.get(1); todaysDayActivity = dayActivities.get(0); } // Double check yesterday's activity List<Activity> yesterdaysActivities = yesterdaysDayActivity.getActivities(); assertThat("One activity created for yesterday", yesterdaysActivities.size(), equalTo(1)); Activity yesterdaysActivity = yesterdaysActivities.get(0); assertThat("Expect right goal set to yesterday's activity", yesterdaysActivity.getActivityCategory(), equalTo(gamblingGoal.getActivityCategory())); // Verify one activity was created, with the right goal List<Activity> activities = todaysDayActivity.getActivities(); assertThat("One activity created", activities.size(), equalTo(1)); Activity activity = activities.get(0); assertThat("Expect right goal set to activity", activity.getActivityCategory(), equalTo(gamblingGoal.getActivityCategory())); assertThat("Expect new day", todaysDayActivity, not(equalTo(existingDayActivity))); assertThat("Expect right date", todaysDayActivity.getStartDate(), equalTo(today.toLocalDate())); assertThat("Expect activity added", todaysDayActivity.getLastActivity(deviceAnonId), notNullValue()); assertThat("Expect matching start time", todaysDayActivity.getLastActivity(deviceAnonId).getStartTime(), equalTo(startTime.toLocalDateTime())); assertThat("Expect matching end time", todaysDayActivity.getLastActivity(deviceAnonId).getEndTime(), equalTo(endTime.toLocalDateTime())); // Verify that there is an activity cached verify(mockAnalysisEngineCacheService, atLeastOnce()).updateLastActivityForUser(eq(userAnonId), eq(deviceAnonId), eq(gamblingGoal.getId()), any()); }