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:com.ning.billing.invoice.dao.DefaultInvoiceDao.java

License:Apache License

@Override
public List<InvoiceModelDao> getInvoicesByAccount(final UUID accountId, final LocalDate fromDate,
        final InternalTenantContext context) {
    return transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<List<InvoiceModelDao>>() {
        @Override//from   w  ww . j ava2  s . c  o m
        public List<InvoiceModelDao> inTransaction(
                final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
            final InvoiceSqlDao invoiceDao = entitySqlDaoWrapperFactory.become(InvoiceSqlDao.class);

            final List<InvoiceModelDao> invoices = invoiceDao.getInvoicesByAccountAfterDate(
                    accountId.toString(), fromDate.toDateTimeAtStartOfDay().toDate(), context);
            invoiceDaoHelper.populateChildren(invoices, entitySqlDaoWrapperFactory, context);

            return invoices;
        }
    });
}

From source file:com.qcadoo.mes.assignmentToShift.hooks.AssignmentToShiftHooks.java

License:Open Source License

private Set<LocalDate> findNextStartDatesMatching(final DataDefinition assignmentToShiftDD, final Shift shift,
        final LocalDate laterThan) {
    AssignmentToShiftCriteria criteria = AssignmentToShiftCriteria.empty();
    criteria.withCriteria(gt(AssignmentToShiftFields.START_DATE, laterThan.toDate()));
    criteria.withShiftCriteria(idEq(shift.getId()));
    List<Entity> matchingStartDatesProjection = assignmentToShiftDataProvider.findAll(criteria,
            Optional.of(alias(field(AssignmentToShiftFields.START_DATE), AssignmentToShiftFields.START_DATE)),
            Optional.of(asc(AssignmentToShiftFields.START_DATE)));

    return FluentIterable.from(matchingStartDatesProjection)
            .transform(EntityUtils.<Date>getFieldExtractor(AssignmentToShiftFields.START_DATE))
            .transform(TO_LOCAL_DATE).toSet();
}

From source file:com.qcadoo.mes.productionPerShift.dataProvider.ProgressForDayDataProvider.java

License:Open Source License

public Optional<Entity> findForOperationAndActualDate(final TechnologyOperationId tocId,
        final ProgressType progressType, final LocalDate day) {
    SearchCriteriaBuilder pfdCriteriaBuilder = getPfdDataDefinition().find();
    pfdCriteriaBuilder.add(eq(ProgressForDayFields.CORRECTED, progressType == ProgressType.CORRECTED));
    pfdCriteriaBuilder.add(belongsTo(ProgressForDayFields.TECHNOLOGY_OPERATION_COMPONENT,
            TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT,
            tocId.get()));//from  ww w  .ja v  a 2  s .c  o  m
    pfdCriteriaBuilder.add(eq(ProgressForDayFields.ACTUAL_DATE_OF_DAY, day.toDate()));
    return Optional.ofNullable(pfdCriteriaBuilder.setMaxResults(1).uniqueResult());
}

From source file:com.rappsantiago.weighttracker.goal.EditGoalsFragment.java

License:Apache License

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    LocalDate date = new LocalDate(year, monthOfYear + 1, dayOfMonth);
    mDueDateInMillis = date.toDate().getTime();
    mLblDueDate.setText(DisplayUtil.getReadableDate(mDueDateInMillis));
}

From source file:com.rappsantiago.weighttracker.profile.setup.NameBirthdayGenderFragment.java

License:Apache License

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    LocalDate date = new LocalDate(year, monthOfYear + 1, dayOfMonth);
    mBirthdayInMillis = date.toDate().getTime();
    mLblBirthday.setText(DisplayUtil.getReadableDate(mBirthdayInMillis));
}

From source file:com.rappsantiago.weighttracker.progress.AddEditProgressFragment.java

License:Apache License

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    LocalDate date = new LocalDate(year, monthOfYear + 1, dayOfMonth);
    mDateInMillis = date.toDate().getTime();
    mLblDate.setText(DisplayUtil.getReadableDate(mDateInMillis));
}

From source file:com.rappsantiago.weighttracker.util.Util.java

License:Apache License

public static long getCurrentDateInMillis() {
    LocalDate localDate = new LocalDate();
    return localDate.toDate().getTime();
}

From source file:com.sonicle.webtop.core.jooq.LocalDateConverter.java

License:Open Source License

@Override
public Date to(LocalDate u) {
    return (u == null) ? null : new Date(u.toDate().getTime());
}

From source file:com.squid.kraken.v4.api.core.EngineUtils.java

License:Open Source License

/**
 * Convert the facet value into a date. 
 * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant.
 * @param ctx/*from ww w  . j  a v a  2  s. c o  m*/
 * @param index
 * @param lower 
 * @param value
 * @param compareFromInterval 
 * @return
 * @throws ParseException
 * @throws ScopeException
 * @throws ComputingException 
 */
public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value,
        IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException {
    if (value.equals("")) {
        return null;
    } else if (value.startsWith("__")) {
        //
        // support hard-coded shortcuts
        if (value.toUpperCase().startsWith("__COMPARE_TO_")) {
            // for compareTo
            if (compareFromInterval == null) {
                // invalid compare_to selection...
                return null;
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                if (bound == Bound.UPPER) {
                    LocalDate date = localLower.minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate date = localLower.minusDays(1 + days.getDays());
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusMonths(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusYears(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
        } else {
            // for regular
            // get MIN, MAX first
            Intervalle range = null;
            if (index.getDimension().getType() == Type.CONTINUOUS) {
                if (index.getStatus() == Status.DONE) {
                    List<DimensionMember> members = index.getMembers();
                    if (!members.isEmpty()) {
                        DimensionMember member = members.get(0);
                        Object object = member.getID();
                        if (object instanceof Intervalle) {
                            range = (Intervalle) object;
                        }
                    }
                } else {
                    try {
                        DomainHierarchy hierarchy = universe
                                .getDomainHierarchy(index.getAxis().getParent().getDomain());
                        hierarchy.isDone(index, null);
                    } catch (ComputingException | InterruptedException | ExecutionException
                            | TimeoutException e) {
                        throw new ComputingException("failed to retrieve period interval");
                    }
                }
            }
            if (range == null) {
                range = IntervalleObject.createInterval(new Date(), new Date());
            }
            if (value.equalsIgnoreCase("__ALL")) {
                if (index.getDimension().getType() != Type.CONTINUOUS) {
                    return null;
                }
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getLowerBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_DAY")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getUpperBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_7_DAYS")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.minusDays(6);// 6+1
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_MONTH")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_YEAR")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1);
                    return date.toDate();
                }
            }
        }
        throw new ScopeException("undefined facet expression alias: " + value);
    } else if (value.startsWith("=")) {
        // if the value starts by equal token, this is a formula that can be
        // evaluated
        try {
            String expr = value.substring(1);
            // check if the index content is available or wait for it
            DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(),
                    true);
            hierarchy.isDone(index, null);
            // evaluate the expression
            Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval);
            // check we can use it
            if (defaultValue == null) {
                //throw new ScopeException("unable to parse the facet expression as a constant: " + expr);
                // T1769: it's ok to return null
                return null;
            }
            if (!(defaultValue instanceof Date)) {
                throw new ScopeException("unable to parse the facet expression as a date: " + expr);
            }
            // ok, it's a date
            return (Date) defaultValue;
        } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) {
            throw new ComputingException("failed to retrieve period interval");
        }
    } else {
        Date date = ServiceUtils.getInstance().toDate(value);
        if (bound == Bound.UPPER
                && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) {
            // clear the timestamp
            return new LocalDate(date.getTime()).toDate();
        } else {
            return date;
        }
    }
}

From source file:com.squid.kraken.v4.core.analysis.datamatrix.CompareMerger.java

License:Open Source License

@Override
protected Object translateRightToLeft(Object right) {
    if (right instanceof Date && offset != null) {
        LocalDate delta = (new LocalDate(((Date) right).getTime())).plus(offset);
        return new java.sql.Date(delta.toDate().getTime());
    } else {//www.  j  a va 2s  .  c o  m
        return right;
    }
}