/** * Converts this LocalDate to a full datetime at the earliest valid time * for the date using the default time zone. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return this date as a datetime at the start of the day * @since 1.5 */ public DateTime toDateTimeAtStartOfDay() { return toDateTimeAtStartOfDay(null); }
/** * Converts this LocalDate to a full datetime at the earliest valid time * for the date using the default time zone. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return this date as a datetime at the start of the day * @since 1.5 */ public DateTime toDateTimeAtStartOfDay() { return toDateTimeAtStartOfDay(null); }
@Override public void removedExpiredAccounts(LocalDate reference) { template.update("DELETE Account AS a WHERE a.expiryDate < ?", reference.toDateTimeAtStartOfDay().toDate()); } }
import org.joda.time.Chronology; import org.joda.time.LocalDate; import org.joda.time.chrono.IslamicChronology; import org.joda.time.chrono.ISOChronology; public class Test { public static void main(String[] args) throws Exception { Chronology iso = ISOChronology.getInstanceUTC(); Chronology hijri = IslamicChronology.getInstanceUTC(); LocalDate todayIso = new LocalDate(2013, 3, 31, iso); LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(), hijri); System.out.println(todayHijri); // 1434-05-19 } }
public static BooleanExpression expiresBefore(LocalDate date) { return account.expiryDate.before(date.toDateTimeAtStartOfDay().toDate()); } }
@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(cb.lessThan(account.get("expiryDate").as(Date.class), reference.toDateTimeAtStartOfDay().toDate())); for (Account each : em.createQuery(query).getResultList()) { em.remove(each); } } }
@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); } };
public void setValue(Object value, ValueFields valueFields) { if (value != null) { valueFields.setLongValue(((LocalDate) value).toDateTimeAtStartOfDay().getMillis()); } else { valueFields.setLongValue(null); } } }
/** * Converts this object to an Interval representing the whole day. * <p> * The interval may have more or less than 24 hours if this is a daylight * savings cutover date. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toDateTimeAtStartOfDay(zone); DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this object to an Interval representing the whole day. * <p> * The interval may have more or less than 24 hours if this is a daylight * savings cutover date. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toDateTimeAtStartOfDay(zone); DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Converts this object to an Interval representing the whole month. * <p> * The interval will use the chronology of the year-month in the specified zone. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return an interval over the month, never null */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toLocalDate(1).toDateTimeAtStartOfDay(zone); DateTime end = plusMonths(1).toLocalDate(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this object to an Interval representing the whole month. * <p> * The interval will use the chronology of the year-month in the specified zone. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return an interval over the month, never null */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toLocalDate(1).toDateTimeAtStartOfDay(zone); DateTime end = plusMonths(1).toLocalDate(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Converts this LocalDate to a full datetime at the earliest valid time * for the date using the default time zone. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return this date as a datetime at the start of the day * @since 1.5 */ public DateTime toDateTimeAtStartOfDay() { return toDateTimeAtStartOfDay(null); }
@Override public long convertToMillis(LocalDate value) { return value.toDateTimeAtStartOfDay().getMillis(); }
@Override public Object toDatabaseParam(LocalDate val) { return new java.sql.Date(val.toDateTimeAtStartOfDay().getMillis()); } }
/** * Converts this object to an Interval representing the whole day. * <p> * The interval may have more or less than 24 hours if this is a daylight * savings cutover date. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return a interval over the day */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toDateTimeAtStartOfDay(zone); DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }
/** * Returns a copy of this datetime with the time set to the start of the day. * <p> * The time will normally be midnight, as that is the earliest time on * any given day. However, in some time zones when Daylight Savings Time * starts, there is no midnight because time jumps from 11:59 to 01:00. * This method handles that situation by returning 01:00 on that date. * <p> * This instance is immutable and unaffected by this method call. * * @return a copy of this datetime with the time set to the start of the day, not null */ public DateTime withTimeAtStartOfDay() { return toLocalDate().toDateTimeAtStartOfDay(getZone()); }
/** * Converts this object to an Interval representing the whole month. * <p> * The interval will use the chronology of the year-month in the specified zone. * <p> * This instance is immutable and unaffected by this method call. * * @param zone the zone to get the Interval in, null means default * @return an interval over the month, never null */ public Interval toInterval(DateTimeZone zone) { zone = DateTimeUtils.getZone(zone); DateTime start = toLocalDate(1).toDateTimeAtStartOfDay(zone); DateTime end = plusMonths(1).toLocalDate(1).toDateTimeAtStartOfDay(zone); return new Interval(start, end); }