Example usage for org.joda.time LocalDate toDate

List of usage examples for org.joda.time LocalDate toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:energy.usef.test.DatabaseObject.java

License:Apache License

public void setPeriod(LocalDate period) {
    if (period == null) {
        this.period = null;
    } else {/*from w w w  .ja  va  2  s.  c o  m*/
        this.period = period.toDateMidnight().toDate();
    }

}

From source file:es.collectserv.handler.LocalDateTypeHandler.java

License:Apache License

public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
    LocalDate date = (LocalDate) parameter;
    if (date != null) {
        ps.setDate(i, new Date(date.toDateTimeAtStartOfDay().toDate().getTime()));
    } else {//  ww w .j a v a  2  s.  co m
        ps.setDate(i, null);
    }
}

From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java

License:Open Source License

private boolean onDaySelected(LocalDate date) {
    selectedDate = date.toDateTimeAtStartOfDay().toDate();
    return showPickupsInfo(date);
}

From source file:es.usc.citius.servando.calendula.activities.SummaryCalendarActivity.java

License:Open Source License

private void setupCalendar() {

    calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
    calendar.setVerticalScrollBarEnabled(false);

    RepetitionRule r;/*from  w ww  .  j  a  v a  2s.  c o  m*/
    String rule = getIntent().getStringExtra("rule");
    String date = getIntent().getStringExtra("start");

    int activeDays = getIntent().getIntExtra("active_days", -1);
    int restDays = getIntent().getIntExtra("rest_days", -1);

    LocalDate from = date != null ? LocalDate.parse(date, fmt) : LocalDate.now();
    LocalDate to = from.plusMonths(6);

    if (rule != null) {
        r = new RepetitionRule(rule);
        List<DateTime> dates = r.occurrencesBetween(from.toDateTimeAtStartOfDay(), to.toDateTimeAtStartOfDay(),
                from.toDateTimeAtStartOfDay());
        Set<Date> hdates = new HashSet<>();
        for (DateTime d : dates)
            hdates.add(d.toDate());

        List<CalendarCellDecorator> decorators = new ArrayList<>();

        DateValue v = r.iCalRule().getUntil();
        Date start = date != null ? from.toDate() : null;
        Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null;

        decorators.add(new HighlightDecorator(new ArrayList<>(hdates), start, end, color));
        calendar.setDecorators(decorators);
    } else if (activeDays > 0 && restDays > 0) {

        List<Date> hdates = new ArrayList<>();

        LocalDate d = from.plusDays(0); // copy

        while (d.isBefore(to)) {
            if (ScheduleHelper.cycleEnabledForDate(d, from, activeDays, restDays)) {
                hdates.add(d.toDate());
            }
            d = d.plusDays(1);
        }

        List<CalendarCellDecorator> decorators = new ArrayList<>();
        //DateValue v = r.iCalRule().getUntil();
        //Date start = date != null ? from.toDate() : null;
        //Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null;
        decorators.add(new HighlightDecorator(hdates, from.toDate(), to.toDate(), color));
        calendar.setDecorators(decorators);
    }

    calendar.init(from.toDate(), to.toDate())
            .setShortWeekdays(getResources().getStringArray(R.array.calendar_weekday_names));
}

From source file:eu.uqasar.util.ModelInitializer.java

License:Apache License

private Date getBirthday(int year, int month, int day) {
    LocalDate date = new LocalDate(year, month, day);
    return date.toDate();
}

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(/* w  ww. j a  v a2s.c om*/
            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.
 * /*from   w  ww  .  ja v  a  2  s .  com*/
 * @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:facades.WatchFacade.java

public SamaritOccupied getWatchesForDateUser(String date, String userName) {
    EntityManager em = EntityConnector.getEntityManager();
    SamaritOccupied watch = null;/*from  www  .  ja  v  a 2s .  c  o m*/
    List<SamaritOccupied> watches;
    LocalDate dstart = dtf.parseLocalDate(date);
    LocalDate dstart1 = dstart.plusDays(1);

    Date d1 = dstart.toDate();
    Date d2 = dstart1.toDate();

    try {
        Query q = em.createQuery(
                "SELECT w FROM SamaritOccupied AS w WHERE w.samarit.userName = ?1 AND w.start >= ?2 AND w.start < ?3"); // AND w.start = :date

        q.setParameter(1, userName);
        q.setParameter(2, d1);
        q.setParameter(3, d2);
        watches = q.getResultList();

        for (SamaritOccupied watche : watches) {

            if (watche.isAllDay()) {
                deleteWatch(watche.getId());
                watch = watche;
            }
        }
    } catch (Exception e) {
        log.Log.writeErrorMessageToLog("Error in getwatches for User: " + e.getMessage());
        throw e;
    } finally {
        em.close();
    }
    return watch;
}