List of usage examples for org.joda.time LocalDate toDateTimeAtStartOfDay
public DateTime toDateTimeAtStartOfDay()
From source file:example.springdata.jpa.showcase.snippets.AccountPredicates.java
License:Apache License
public static BooleanExpression expiresBefore(LocalDate date) { return account.expiryDate.before(date.toDateTimeAtStartOfDay().toDate()); }
From source file:example.springdata.jpa.showcase.snippets.AccountRepositoryImpl.java
License:Apache License
@Override public void removedExpiredAccounts(LocalDate reference) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Account> query = cb.createQuery(Account.class); Root<Account> account = query.from(Account.class); query.where(//from ww w . j a v a 2 s . co m cb.lessThan(account.get("expiryDate").as(Date.class), reference.toDateTimeAtStartOfDay().toDate())); for (Account each : em.createQuery(query).getResultList()) { em.remove(each); } }
From source file:example.springdata.jpa.showcase.snippets.AccountRepositoryJdbcImpl.java
License:Apache License
@Override public void removedExpiredAccounts(LocalDate reference) { template.update("DELETE Account AS a WHERE a.expiryDate < ?", reference.toDateTimeAtStartOfDay().toDate()); }
From source file:example.springdata.jpa.showcase.snippets.CustomerSpecifications.java
License:Apache License
/** * All customers with an {@link Account} expiring before the given date. * //w ww .j a va2s.co m * @param date * @return */ public static Specification<Customer> accountExpiresBefore(final LocalDate date) { return new Specification<Customer>() { @Override public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Root<Account> accounts = query.from(Account.class); Path<Date> expiryDate = accounts.<Date>get("expiryDate"); Predicate customerIsAccountOwner = cb.equal(accounts.<Customer>get("customer"), root); Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate()); return cb.and(customerIsAccountOwner, accountExpiryDateBefore); } }; }
From source file:fi.hsl.parkandride.back.FacilityHistoryDao.java
License:EUPL
@Override @TransactionalRead// www . j a va2 s. com public List<FacilityStatusHistory> getStatusHistory(long facilityId, LocalDate startInclusive, LocalDate endInclusive) { return getStatusHistoryQuery(facilityId).where(qFacilityStatusHistory.startTs .loe(endInclusive.toDateTimeAtStartOfDay().millisOfDay().withMaximumValue()) .andAnyOf(qFacilityStatusHistory.endTs.isNull(), qFacilityStatusHistory.endTs.goe(startInclusive.toDateTimeAtStartOfDay()))) .fetch(); }
From source file:fi.hsl.parkandride.back.FacilityHistoryDao.java
License:EUPL
@Override @TransactionalRead/*from w ww . j a va2s . co m*/ public List<FacilityCapacityHistory> getCapacityHistory(long facilityId, LocalDate startInclusive, LocalDate endInclusive) { return getFacilityCapacityHistories(facilityId, q -> q.where(qFacilityCapacityHistory.startTs .loe(endInclusive.toDateTimeAtStartOfDay().millisOfDay().withMaximumValue()) .andAnyOf(qFacilityCapacityHistory.endTs.isNull(), qFacilityCapacityHistory.endTs.goe(startInclusive.toDateTimeAtStartOfDay())))); }
From source file:fi.hsl.parkandride.core.service.reporting.RequestLogReportService.java
License:EUPL
private List<RequestLogEntry> getRowsForDates(LocalDate startDate, LocalDate endDate, RequestLogInterval interval) {//from www . jav a 2 s . co m final DateTime start = startDate.toDateTimeAtStartOfDay(); final DateTime end = endDate.toDateTimeAtStartOfDay().millisOfDay().withMaximumValue(); validate(start).lte(end); final List<RequestLogEntry> logEntriesBetween = requestLogRepository.getLogEntriesBetween(start, end); return logEntriesBetween.stream().collect(groupingBy(entry -> interval.apply(entry.key))).entrySet() .stream().map(groupedEntry -> { final RequestLogKey key = groupedEntry.getKey(); final Long totalCount = groupedEntry.getValue().stream() .collect(summingLong(entry -> entry.count)); return new RequestLogEntry(key, totalCount); }).sorted(comparing(entry -> entry.key)).collect(toList()); }
From source file:fi.vm.sade.osoitepalvelu.kooste.scheduled.ScheduledOrganisaatioCacheTask.java
License:EUPL
/** * Does not purge fresh cache records but ensures that all organisaatios are cached. *///from w ww . j av a 2 s .c om public void ensureOrganisaatioCacheFresh() { logger.info("BEGIN SCHEDULED ensureOrganisaatioCacheFresh."); showCacheState(); LocalDate cacheInvalidBefore = null; if (cacheValidFrom != null && cacheValidFrom.length() > 0) { cacheInvalidBefore = LocalDate.parse(cacheValidFrom); } // No CAS here (not needed for reading organisaatio service): final DefaultCamelRequestContext context = new DefaultCamelRequestContext( new ProviderOverriddenCasTicketCache(new CasDisabledCasTicketProvider())); if (cacheInvalidBefore != null && new DateTime().compareTo(cacheInvalidBefore.toDateTimeAtStartOfDay()) < 0) { context.setOverriddenTime(cacheInvalidBefore.toDateTimeAtStartOfDay()); } List<String> oids = retryOnCamelError(new Callable<List<String>>() { public List<String> call() { return organisaatioServiceRoute.findAllOrganisaatioOids(context); } }, MAX_TRIES, WAIT_BEFORE_RETRY_MILLIS); removeCachedDeletedOrganisaatios(oids); logger.info("Found {} organisaatios to ensure cache.", oids.size()); boolean infoUpdated = false; try { int i = 0; for (final String oid : oids) { ++i; // ...and renew the cache: long rc = context.getRequestCount(); retryOnCamelError(new Callable<OrganisaatioDetailsDto>() { public OrganisaatioDetailsDto call() { return organisaatioService.getdOrganisaatioByOid(oid, context); } }, MAX_TRIES, WAIT_BEFORE_RETRY_MILLIS); if (rc != context.getRequestCount()) { infoUpdated = true; logger.debug("Updated organisaatio {} (Total: {} / {})", new Object[] { oid, i, oids.size() }); } else if (i % LOGGIN_INTERVAL == 0) { logger.info("Organisaatio ensure data fresh task status: {} / {}", new Object[] { i, oids.size() }); } } } finally { if (infoUpdated) { logger.debug("UPDATING y-tunnus details..."); organisaatioService.updateOrganisaatioYtunnusDetails(context); logger.debug("DONE UPDATING y-tunnus details"); } } logger.info("END SCHEDULED ensureOrganisaatioCacheFresh."); }
From source file:gg.db.datamodel.Period.java
License:Open Source License
/** * Is the specified period valid?/* w ww .ja v a 2 s. c o m*/ * @param startDate Start date of the period * @param endDate End date of the period * @param periodType Type of the period * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/> * To be valid, a period has to be a "full" period: * <UL> * <LI> For each type of period: Start date > End date</LI> * <LI> For DAY period: number of days between Start date and End date = 0<BR/> * Example: <I>From 12/30/2005 to 12/30/2005</I></LI> * <LI> For WEEK period: number of days between Start date and End date = 6<BR/> * The period has to start on MONDAY<BR/> * The period has to end on SUNDAY<BR/> * Example: <I>From 12/01/2005 to 12/18/2005</I></LI> * <LI> For MONTH period: number of month between Start date and End date = 0<BR/> * The period has to start on the first day of the month (05/01/2006)<BR/> * The period has to end on the last day of the month (05/31/2006)<BR/> * Number of months between Start date - 1 day and End date = 1<BR/> * Number of months between Start date and End date + 1 day = 1<BR/> * Example: <I>From 03/01/2005 to 03/31/2005</I></LI> * <LI> For YEAR period: number of years between Start date and End date = 0<BR/> * The period has to start on the first day of the first month (01/01/2006)<BR/> * The period has to end in December<BR/> * The period has to end on the last day of the last month (12/31/2006)<BR/> * Number of years between Start date - 1 day and End date = 1<BR/> * Number of years between Start date and End date + 1 day = 1<BR/> * Example: <I>From 01/01/2006 to 12/31/2006</I></LI> * </UL> */ private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) { boolean periodValid = true; // Is the period valid // Check if Start date < End date if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) { periodValid = false; } // Check if the period is a "full" period if (periodValid && startDate != null && endDate != null && periodType != null) { switch (periodType) { case DAY: // i.e. a DAY period: from 05/12/2006 to 05/12/2006 if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1 (Nb of days = 1) (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0) (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1) periodValid = false; } break; case WEEK: // i.e. a WEEK period: from 05/12/2006 to 05/18/2006 if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1) (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0) (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1) periodValid = false; } break; case MONTH: // i.e. a MONTH period: from 05/01/2006 to 05/30/2006 if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1) (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0) (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1) periodValid = false; } break; case YEAR: // i.e. a YEAR period: from 01/01/2006 to 12/31/2006 if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1) (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0) (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1) periodValid = false; } break; case FREE: // There is no constraint on the number of units for FREE type of period break; default: // Should never happen throw new AssertionError("The PeriodType is unknown"); } } return periodValid; }
From source file:graphene.util.time.JodaTimeUtil.java
License:Apache License
public static java.util.Date toJavaDate(final LocalDate ld) { // TODO - confirm this conversion always works, esp. across timezones final java.util.Date d = (ld == null ? null : new java.util.Date(ld.toDateTimeAtStartOfDay().getMillis())); return d;//from w w w .j a v a 2 s . c om }