List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:org.silverpeas.core.calendar.CalendarSynchronizationIT.java
@Test public void synchronizeFromANonEmptyCalendarShouldAddAllEvents() throws Exception { Calendar calendar = prepareCalendarWithExternal(externalUrl); ICalendarImportResult result = calendar.synchronize(); assertThat(result.added(), is(2));//from ww w . j av a2 s . c o m assertThat(result.updated(), is(0)); assertThat(result.deleted(), is(0)); final Calendar synchronizedCalendar = Calendar.getById(CALENDAR_ID); assertThat(synchronizedCalendar.getLastSynchronizationDate().isPresent(), is(true)); assertThat(synchronizedCalendar.getLastSynchronizationDate().get().toLocalDate(), is(LocalDate.now())); assertThat(synchronizedCalendar.isEmpty(), is(false)); List<CalendarEvent> events = Calendar.getEvents().filter(f -> f.onCalendar(synchronizedCalendar)).stream() .collect(Collectors.toList()); assertThat(events.size(), is(2)); events.forEach(e -> { assertThat(e.getLastSynchronizationDate().toLocalDate(), is(LocalDate.now())); }); }
From source file:com.fantasy.stataggregator.workers.GameDataRetrieverTask.java
/** * Determines if a game has already been played, No current game data<br> * will be pulled, since the statistics aren't final. * * @param sched//from w ww.ja va 2 s.c o m * @return */ private boolean hasBeenPlayed(GameSchedule sched) throws ParseException { Date gameDate = sched.getGamedate(); if (Objects.nonNull(gameDate)) { LocalDate dateOnly = LocalDateTime.ofInstant(gameDate.toInstant(), ZoneId.systemDefault()) .toLocalDate(); return dateOnly.isBefore(LocalDate.now()); } return false; }
From source file:fi.helsinki.opintoni.SpringTest.java
protected TeacherRequestChain teacherRequestChain(String teacherNumber) { return new TeacherRequestChain(teacherNumber, DateTimeUtil.getSemesterStartDateString(LocalDate.now()), oodiServer, coursePageServer); }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
@Test public void testReserveFromExistingCategoryNotEnoughSeatsBounded() throws Exception { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); performExistingCategoryTest(categories, true, Collections.singletonList(2), false, true, 0, AVAILABLE_SEATS);/* ww w .ja va 2 s . c om*/ }
From source file:com.romeikat.datamessie.core.base.ui.page.StatisticsPage.java
private LocalDate getFromDate() { final LocalDate toDate = getToDate(); if (toDate == null) { return LocalDate.now(); }/*from www . j a v a 2s. co m*/ Integer statisticsPeriod = DataMessieSession.get().getStatisticsPeriodModel().getObject(); if (statisticsPeriod == null) { return LocalDate.now(); } final StatisticsInterval statisticsInterval = DataMessieSession.get().getStatisticsIntervalModel() .getObject(); if (statisticsInterval == null) { return LocalDate.now(); } // Minimum value is 1 statisticsPeriod = Math.max(statisticsPeriod, 1); // Calculate final LocalDate fromDate = toDate.plusDays(1); switch (statisticsInterval) { case DAY: return fromDate.minusDays(statisticsPeriod); case WEEK: return fromDate.minusWeeks(statisticsPeriod); case MONTH: return fromDate.minusMonths(statisticsPeriod); case YEAR: return fromDate.minusYears(statisticsPeriod); default: return LocalDate.now(); } }
From source file:se.inera.intyg.intygstjanst.persistence.model.dao.impl.SjukfallCertificateDaoImplTest.java
private List<SjukfallCertificateWorkCapacity> defaultWorkCapacities() { List<SjukfallCertificateWorkCapacity> workCapacities = new ArrayList<>(); SjukfallCertificateWorkCapacity wc = new SjukfallCertificateWorkCapacity(); wc.setCapacityPercentage(100);/*from w w w. ja v a2s . c om*/ wc.setFromDate(LocalDate.now().minusWeeks(1).format(DateTimeFormatter.ISO_DATE)); wc.setToDate(LocalDate.now().plusWeeks(1).format(DateTimeFormatter.ISO_DATE)); workCapacities.add(wc); SjukfallCertificateWorkCapacity wc2 = new SjukfallCertificateWorkCapacity(); wc2.setCapacityPercentage(75); wc2.setFromDate(LocalDate.now().minusWeeks(3).format(DateTimeFormatter.ISO_DATE)); wc2.setToDate(LocalDate.now().minusWeeks(1).format(DateTimeFormatter.ISO_DATE)); workCapacities.add(wc2); SjukfallCertificateWorkCapacity wc3 = new SjukfallCertificateWorkCapacity(); wc3.setCapacityPercentage(50); wc3.setFromDate(LocalDate.now().minusWeeks(4).format(DateTimeFormatter.ISO_DATE)); wc3.setToDate(LocalDate.now().minusWeeks(3).format(DateTimeFormatter.ISO_DATE)); workCapacities.add(wc3); return workCapacities; }
From source file:org.openmhealth.shim.googlefit.GoogleFitShim.java
protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final GoogleFitDataTypes googleFitDataType; try {// w w w.j av a 2s . co m googleFitDataType = GoogleFitDataTypes.valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase()); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey() + " in shimDataRequest, cannot retrieve data."); } OffsetDateTime todayInUTC = LocalDate.now().atStartOfDay().atOffset(ZoneOffset.UTC); OffsetDateTime startDateInUTC = shimDataRequest.getStartDateTime() == null ? todayInUTC.minusDays(1) : shimDataRequest.getStartDateTime(); long startTimeNanos = (startDateInUTC.toEpochSecond() * 1000000000) + startDateInUTC.toInstant().getNano(); OffsetDateTime endDateInUTC = shimDataRequest.getEndDateTime() == null ? todayInUTC.plusDays(1) : shimDataRequest.getEndDateTime().plusDays(1); // We are inclusive of the last day, so add 1 day to get // the end of day on the last day, which captures the // entire last day long endTimeNanos = (endDateInUTC.toEpochSecond() * 1000000000) + endDateInUTC.toInstant().getNano(); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .pathSegment(googleFitDataType.getStreamId(), "datasets", "{startDate}-{endDate}"); // TODO: Add limits back into the request once Google has fixed the 'limit' query parameter and paging URI uriRequest = uriBuilder.buildAndExpand(startTimeNanos, endTimeNanos).encode().toUri(); ResponseEntity<JsonNode> responseEntity; try { responseEntity = restTemplate.getForEntity(uriRequest, JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // TODO figure out how to handle this logger.error("A request for Google Fit data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { GoogleFitDataPointMapper<?> dataPointMapper; switch (googleFitDataType) { case BODY_WEIGHT: dataPointMapper = new GoogleFitBodyWeightDataPointMapper(); break; case BODY_HEIGHT: dataPointMapper = new GoogleFitBodyHeightDataPointMapper(); break; case ACTIVITY: dataPointMapper = new GoogleFitPhysicalActivityDataPointMapper(); break; case STEP_COUNT: dataPointMapper = new GoogleFitStepCountDataPointMapper(); break; case HEART_RATE: dataPointMapper = new GoogleFitHeartRateDataPointMapper(); break; case CALORIES_BURNED: dataPointMapper = new GoogleFitCaloriesBurnedDataPointMapper(); break; default: throw new UnsupportedOperationException(); } return ok().body(ShimDataResponse.result(GoogleFitShim.SHIM_KEY, dataPointMapper.asDataPoints(singletonList(responseEntity.getBody())))); } else { return ok().body(ShimDataResponse.result(GoogleFitShim.SHIM_KEY, responseEntity.getBody())); } }
From source file:bzzAgent.BiteSizedBzzDaoJpa.java
@Override public List<BsbAgentActivityEntity> getBsbAgentActivities(BsbAgentActivitySearchParams params) { Validate.notBlank(params.getUsername(), "username was missing"); Validate.isTrue(params.getStatusList().size() > 0, "no statuses were passed"); final String orderString; final String sortOrder = params.getSortorder().toString(); switch (params.getOrderby()) { case lastmodified: orderString = " bsbaae.lastModified " + sortOrder; break;/*from w ww. j a va2 s .c o m*/ case priority: if (params.getSortorder() == SortOrder.asc) { orderString = " bsbaae.clientSponsored asc, bsbaae.endDate desc"; } else { orderString = " bsbaae.clientSponsored desc, bsbaae.endDate asc"; } break; default: throw new RuntimeException( "unhandled case for BsbAgentActivitySearchParams.orderBy=" + params.getOrderby()); } final List<Integer> statusList = new ArrayList<>(); for (BsbActivityStatus bsbActivityStatus : params.getStatusList()) { final CampaignInviteStatus campaignInviteStatus = BsbActivityStatus .toCampaignInviteStatus(bsbActivityStatus); if (campaignInviteStatus != null) { statusList.add(campaignInviteStatus.getValue()); } } final LocalDate today = LocalDate.now(); final StringBuilder sql = new StringBuilder("from BsbAgentActivityEntity bsbaae ") .append(" left join fetch bsbaae.incentives incentive ") .append(" left join fetch bsbaae.ecommerceRetailers ecommerceRetailers ") .append(" where bsbaae.username = :username ") .append(" and bsbaae.campaignInviteStatus in :statusList") .append(" and bsbaae.startDate <= :today and bsbaae.endDate >= :today").append(" order by ") .append(orderString); final TypedQuery<BsbAgentActivityEntity> query2 = em .createQuery(sql.toString(), BsbAgentActivityEntity.class) .setParameter("username", params.getUsername()).setParameter("today", today) .setParameter("statusList", statusList); if (params.getLimit() != null && params.getLimit() > 0) { query2.setMaxResults(params.getLimit()); } return query2.getResultList(); }
From source file:com.romeikat.datamessie.core.base.ui.page.AbstractDocumentsFilterPage.java
private LocalDate parseLocalDate(final StringValue stringValue) { final LocalDate today = LocalDate.now(); // No date corresponds to today if (stringValue == null) { return today; }/* w w w.j a va2s.c o m*/ // 0 corresponds to no date if (stringValue.toString().equals("0")) { return null; } // Negative numbers correspond to number of days from today in the past try { final int numberOfDays = Integer.parseInt(stringValue.toString()); if (numberOfDays < 0) { final LocalDate localDate = today.plusDays(numberOfDays); return localDate; } } catch (final NumberFormatException e) { } // Date pattern final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd"); try { final LocalDate localDate = LocalDate.parse(stringValue.toString(), dateFormatter); return localDate; } catch (final IllegalArgumentException ex) { } // Ohterwise, use today return today; }
From source file:com.yqboots.menu.core.MenuItemManagerImpl.java
/** * {@inheritDoc}/* ww w . j av a 2 s. co m*/ */ @Override public Path exports() throws IOException { final String fileName = properties.getExportFileNamePrefix() + LocalDate.now() + FileType.DOT_XML; if (!Files.exists(properties.getExportFileLocation())) { Files.createDirectories(properties.getExportFileLocation()); } final Path result = Paths.get(properties.getExportFileLocation() + File.separator + fileName); final List<MenuItem> menuItems = menuItemRepository.findAll(); try (FileWriter writer = new FileWriter(result.toFile())) { jaxb2Marshaller.marshal(new MenuItems(menuItems), new StreamResult(writer)); } return result; }