Example usage for org.joda.time DateTime toLocalDate

List of usage examples for org.joda.time DateTime toLocalDate

Introduction

In this page you can find the example usage for org.joda.time DateTime toLocalDate.

Prototype

public LocalDate toLocalDate() 

Source Link

Document

Converts this object to a LocalDate with the same date and chronology.

Usage

From source file:nz.co.jsrsolutions.util.QuoteDateComparator.java

License:Open Source License

@Override
public int compare(QUOTE o1, QUOTE o2) {

    final DateTime first = new DateTime(o1.getDateTime());
    final DateTime second = new DateTime(o2.getDateTime());

    final LocalDate firstDate = first.toLocalDate();
    final LocalDate secondDate = second.toLocalDate();

    return firstDate.compareTo(secondDate);

}

From source file:org.alfresco.po.share.workflow.WorkFlowPage.java

License:Open Source License

/**
 * Method to select a date from Calender date picker. The date should be in
 * "dd/MM/yyyy" format/*from   w  w w. ja v a  2s  .  c  o m*/
 * 
 * @param date String
 */
public void selectDateFromCalendar(String date) throws InterruptedException {
    if (StringUtils.isEmpty(date)) {
        throw new IllegalArgumentException("Date cannot be empty");
    }
    DateTime dueDate;
    int due;
    try {
        dueDate = DateTimeFormat.forPattern("dd/MM/yyyy").parseDateTime(date);
        due = dueDate.getDayOfMonth();
    } catch (IllegalArgumentException iae) {
        throw new IllegalArgumentException("Due date should be in \"dd/MM/yyyy\" format");
    }

    try {
        DateTime today = new DateTime();

        waitForElement(DUE_DATED_PICKER, SECONDS.convert(maxPageLoadingTime, MILLISECONDS));
        driver.findElement(DUE_DATED_PICKER).click();

        if (dueDate.isBeforeNow() && !dueDate.toLocalDate().toString(DateTimeFormat.forPattern("dd-MM-yyyy"))
                .equals(today.toLocalDate().toString(DateTimeFormat.forPattern("dd-MM-yyyy")))) {
            throw new UnsupportedOperationException("Due date cannot be in past");
        } else {

            WebElement calenderElement = findAndWait(By.cssSelector("table[id$='_workflowDueDate-cntrl']"));
            waitForElement(By.cssSelector("a.calnav"), SECONDS.convert(maxPageLoadingTime, MILLISECONDS));
            calenderElement.findElement(By.cssSelector("a.calnav")).click();

            WebElement monthAndYearSelector = findAndWait(By.cssSelector("div.yui-cal-nav"));

            Select monthSelector = new Select(
                    driver.findElement(By.cssSelector("select[id$='_workflowDueDate-cntrl_nav_month']")));
            monthSelector.selectByValue(String.valueOf(dueDate.getMonthOfYear() - 1));

            monthAndYearSelector.findElement(By.cssSelector("input[id$='_workflowDueDate-cntrl_nav_year']"))
                    .clear();
            monthAndYearSelector.findElement(By.cssSelector("input[id$='_workflowDueDate-cntrl_nav_year']"))
                    .sendKeys(String.valueOf(dueDate.getYear()));

            monthAndYearSelector.findElement(By.cssSelector("button[id$='_workflowDueDate-cntrl_nav_submit']"))
                    .click();

            // Wait for the title to show the month
            waitUntilVisible(By.cssSelector("a.calnav"),
                    dueDate.toString(DateTimeFormat.forPattern("MMMM yyyy")),
                    SECONDS.convert(maxPageLoadingTime, MILLISECONDS));
            calenderElement = findAndWait(By.cssSelector("table[id$='_workflowDueDate-cntrl']>tbody"));

            List<WebElement> allDays = calenderElement.findElements(By.cssSelector("a.selector"));

            for (WebElement day : allDays) {
                if (Integer.parseInt(day.getText()) == (due)) {
                    day.click();
                    break;
                }
            }
        }
    } catch (NoSuchElementException nse) {
        throw new PageOperationException("Unable to find element: ", nse);
    } catch (TimeoutException te) {
        throw new PageOperationException("Timed out on waiting for: ", te);
    }

}

From source file:org.apache.bigtop.datagenerators.weatherman.internal.Driver.java

License:Apache License

/**
 * Returns local date from string in YYYY-MM-DD format
 *
 * @param text/*from ww  w.  jav  a  2  s.c  o  m*/
 * @return
 */
private LocalDate parseDate(String text) {
    DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTime dt = dtFormatter.parseDateTime(text);

    return dt.toLocalDate();
}

From source file:org.apereo.portal.events.aggr.action.JpaSearchRequestAggregationDao.java

License:Apache License

@Override
public final List<SearchRequestAggregationImpl> getAggregations(DateTime start, DateTime end,
        AggregationInterval interval, AggregatedGroupMapping aggregatedGroupMapping,
        AggregatedGroupMapping... aggregatedGroupMappings) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }//from ww  w  .  ja v a  2 s . co m
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();

    final TypedQuery<SearchRequestAggregationImpl> query = this
            .createQuery(this.findAllSearchRequestAggregationsByDateRangeQuery);

    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());

    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));

    query.setParameter(this.intervalParameter, interval);

    final Set<AggregatedGroupMapping> groups = ImmutableSet.<AggregatedGroupMapping>builder()
            .add(aggregatedGroupMapping).add(aggregatedGroupMappings).build();
    query.setParameter(this.aggregatedGroupsParameter, groups);

    return query.getResultList();
}

From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDao.java

License:Apache License

@Override
public final List<T> getAggregations(DateTime start, DateTime end, Set<K> keys,
        AggregatedGroupMapping... aggregatedGroupMappings) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }//from   w w  w .  jav  a 2 s .c o  m
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();

    final TypedQuery<T> query = this.createQuery(findAggregationsByDateRangeQuery);

    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());

    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));

    // Get the first key to use for the interval
    K key = keys.iterator().next();
    query.setParameter(this.intervalParameter, key.getInterval());

    this.bindAggregationSpecificKeyParameters(query, keys);

    final Set<AggregatedGroupMapping> groups = collectAllGroupsFromParams(keys, aggregatedGroupMappings);
    query.setParameter(this.aggregatedGroupsParameter, groups);

    return query.getResultList();
}

From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDao.java

License:Apache License

@Override
public Collection<T> getUnclosedAggregations(DateTime start, DateTime end, AggregationInterval interval) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }/*from ww w  .ja  v  a 2 s  . co  m*/
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();

    final TypedQuery<T> query = this.createQuery(findUnclosedAggregationsByDateRangeQuery);

    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());

    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));

    query.setParameter(this.intervalParameter, interval);

    //Need set to handle duplicate results from join
    return new LinkedHashSet<T>(query.getResultList());
}

From source file:org.apereo.portal.events.aggr.portletlayout.JpaPortletLayoutAggregationDao.java

License:Apache License

public final List<PortletLayoutAggregationImpl> getAggregationsForAllPortlets(DateTime start, DateTime end,
        AggregationInterval interval, AggregatedGroupMapping aggregatedGroupMapping,
        AggregatedGroupMapping... aggregatedGroupMappings) {
    if (!start.isBefore(end)) {
        throw new IllegalArgumentException("Start must be before End: " + start + " - " + end);
    }/*from   w  w w.ja v a2 s.c  o m*/
    final LocalDate startDate = start.toLocalDate();
    final LocalDate endDate = end.toLocalDate();

    final TypedQuery<PortletLayoutAggregationImpl> query = this
            .createQuery(this.findAllPortletAggregationsByDateRangeQuery);

    query.setParameter(this.startDate, startDate);
    query.setParameter(this.startTime, start.toLocalTime());

    query.setParameter(this.endDate, endDate);
    query.setParameter(this.endTime, end.toLocalTime());
    query.setParameter(this.endPlusOneDate, endDate.plusDays(1));

    query.setParameter(this.intervalParameter, interval);

    final Set<AggregatedGroupMapping> groups = ImmutableSet.<AggregatedGroupMapping>builder()
            .add(aggregatedGroupMapping).add(aggregatedGroupMappings).build();
    query.setParameter(this.aggregatedGroupsParameter, groups);

    return query.getResultList();
}

From source file:org.efaps.esjp.ui.dashboard.StatusPanel_Base.java

License:Apache License

@Override
public CharSequence getHtmlSnipplet() throws EFapsException {
    CharSequence ret;//w  w  w. jav a2 s  .c om
    if (isCached()) {
        ret = getFromCache();
    } else {
        final Map<LocalDate, Set<Long>> values = new TreeMap<>();

        final DateTime startDate = new DateTime().minusDays(getDays());

        final QueryBuilder queryBldr = new QueryBuilder(CICommon.HistoryLogin);
        queryBldr.addWhereAttrGreaterValue(CICommon.HistoryLogin.Created, startDate);
        queryBldr.addOrderByAttributeAsc(CICommon.HistoryLogin.Created);
        final MultiPrintQuery multi = queryBldr.getPrint();
        multi.addAttribute(CICommon.HistoryLogin.Created, CICommon.HistoryLogin.GeneralInstanceLink);
        multi.executeWithoutAccessCheck();
        while (multi.next()) {
            final DateTime created = multi.getAttribute(CICommon.HistoryLogin.Created);
            final LocalDate date = created.toLocalDate();
            final Long gId = multi.getAttribute(CICommon.HistoryLogin.GeneralInstanceLink);
            Set<Long> set;
            if (values.containsKey(date)) {
                set = values.get(date);
            } else {
                set = new HashSet<>();
                values.put(date, set);
            }
            set.add(gId);
        }

        final LineChart chart = new LineChart().setLineLayout(LineLayout.LINES).setWidth(getWidth())
                .setHeight(getHeight());
        final String title = getTitle();
        if (title != null && !title.isEmpty()) {
            chart.setTitle(getTitle());
        }
        final Axis xAxis = new Axis().setName("x").addConfig("rotation", "-45");
        chart.addAxis(xAxis);

        final Serie<Data> serie = new Serie<Data>();
        serie.setName("Usuarios").setMouseIndicator(new MouseIndicator());
        ;
        chart.addSerie(serie);

        final List<Map<String, Object>> labels = new ArrayList<>();
        int idx = 1;
        LocalDate current = startDate.toLocalDate();
        while (current.isBefore(new DateTime().plusDays(1).toLocalDate())) {
            int yVal;
            if (values.containsKey(current)) {
                yVal = values.get(current).size();
            } else {
                yVal = 0;
            }
            final Data data = new Data();
            serie.addData(data);
            data.setYValue(yVal).setXValue(idx);
            final Map<String, Object> labelMap = new HashMap<>();
            labelMap.put("value", idx);
            labelMap.put("text", Util
                    .wrap4String(current.toString(getDateFormat(), Context.getThreadContext().getLocale())));
            labels.add(labelMap);
            idx++;
            current = current.plusDays(1);
        }
        xAxis.setLabels(Util.mapCollectionToObjectArray(labels));
        chart.setOrientation(Orientation.HORIZONTAL_LEGEND_CHART);
        ret = chart.getHtmlSnipplet();
        cache(ret);
    }
    return ret;
}

From source file:org.encuestame.business.service.StatisticsService.java

License:Apache License

/**
 *
 * @param detail//from   w ww .  j  a  va2s.c o  m
 * @param dayLabel
 * @return
 */
private boolean checkLabelExistsHashTagDetailStatGraph(final List<HashTagDetailStats> detail,
        final DateTime dayLabel) {
    boolean existLabel = false;

    if (detail.size() > 0) {
        for (HashTagDetailStats hashTagDetailStats : detail) {

            final int detailStat = hashTagDetailStats.getDateValue().toLocalDate()
                    .compareTo(dayLabel.toLocalDate());
            // Values:  0 = Exist 1 = No exists
            if (detailStat == 0) {
                existLabel = true;
            }
        }
    }
    return existLabel;
}

From source file:org.fenixedu.academic.domain.accounting.Event.java

License:Open Source License

public boolean isOpenAndAfterDueDate(DateTime when) {
    DebtInterestCalculator debtInterestCalculator = getDebtInterestCalculator(when);
    return debtInterestCalculator.getDebtsOrderedByDueDate().stream()
            .anyMatch(d -> d.isOpen() && when.toLocalDate().isAfter(d.getDueDate()));
}