Example usage for org.joda.time DateMidnight minusDays

List of usage examples for org.joda.time DateMidnight minusDays

Introduction

In this page you can find the example usage for org.joda.time DateMidnight minusDays.

Prototype

public DateMidnight minusDays(int days) 

Source Link

Document

Returns a copy of this date minus the specified number of days.

Usage

From source file:org.apereo.portal.portlets.statistics.BaseStatisticsReportController.java

License:Apache License

/**
 * Set the start/end date and the interval to have selected by default if they are not already
 * set// w w w  .  j  a  v a 2  s.c o  m
 */
protected final void setReportFormDateRangeAndInterval(final F report) {
    //Determine default interval based on the intervals available for this aggregation
    if (report.getInterval() == null) {
        report.setInterval(AggregationInterval.DAY);
        final Set<AggregationInterval> intervals = this.getIntervals();
        for (final AggregationInterval preferredInterval : PREFERRED_INTERVAL_ORDER) {
            if (intervals.contains(preferredInterval)) {
                report.setInterval(preferredInterval);
                break;
            }
        }
    }

    //Set the report end date as today
    final DateMidnight reportEnd;
    if (report.getEnd() == null) {
        reportEnd = new DateMidnight();
        report.setEnd(reportEnd);
    } else {
        reportEnd = report.getEnd();
    }

    //Determine the best start date based on the selected interval
    if (report.getStart() == null) {
        final DateMidnight start;
        switch (report.getInterval()) {
        case MINUTE: {
            start = reportEnd.minusDays(1);
            break;
        }
        case FIVE_MINUTE: {
            start = reportEnd.minusDays(2);
            break;
        }
        case HOUR: {
            start = reportEnd.minusWeeks(1);
            break;
        }
        case DAY: {
            start = reportEnd.minusMonths(1);
            break;
        }
        case WEEK: {
            start = reportEnd.minusMonths(3);
            break;
        }
        case MONTH: {
            start = reportEnd.minusYears(1);
            break;
        }
        case ACADEMIC_TERM: {
            start = reportEnd.minusYears(2);
            break;
        }
        case CALENDAR_QUARTER: {
            start = reportEnd.minusYears(2);
            break;
        }
        case YEAR: {
            start = reportEnd.minusYears(10);
            break;
        }
        default: {
            start = reportEnd.minusWeeks(1);
        }
        }

        report.setStart(start);
    }
}

From source file:org.jasig.portal.events.aggr.dao.jpa.JpaEventAggregationManagementDao.java

License:Apache License

@Override
@Transactional(value = "aggrEventsTransactionManager", noRollbackFor = IllegalArgumentException.class)
public void addAcademicTermDetails(DateMidnight start, DateMidnight end, String termName) {
    //Check if term dates overlap and fail if they do
    final List<AcademicTermDetail> academicTermDetail = this.getAcademicTermDetails();
    AcademicTermDetail existingTerm = EventDateTimeUtils.findDateRangeSorted(start, academicTermDetail);
    if (existingTerm != null) {
        throw new IllegalArgumentException("Cannot create new term, the start date of " + start
                + " overlaps with existing term: " + existingTerm);
    }//  w  w  w .j  a  v  a  2  s .co  m

    existingTerm = EventDateTimeUtils.findDateRangeSorted(end.minusDays(1), academicTermDetail);
    if (existingTerm != null) {
        throw new IllegalArgumentException("Cannot create new term, the end date of " + end
                + " overlaps with existing term: " + existingTerm);
    }

    final AcademicTermDetailImpl newTerm = new AcademicTermDetailImpl(start, end, termName);
    this.entityManager.persist(newTerm);
}

From source file:org.jasig.portlet.campuslife.dining.mvc.portlet.MainController.java

License:Apache License

@RenderMapping
public ModelAndView showMainView(final RenderRequest request, String date) {

    // determine if the request represents a mobile browser and set the
    // view name accordingly
    final boolean isMobile = viewSelector.isMobile(request);
    final String viewName = isMobile ? "main-jQM" : "main";
    final ModelAndView mav = new ModelAndView("dining/".concat(viewName));

    if (logger.isDebugEnabled()) {
        logger.debug("Using view name " + viewName + " for main view");
    }//from w w  w . j  av a 2 s  . c  o m

    DateMidnight d;
    if (date == null) {
        d = new DateMidnight();
    } else {
        d = paramFormat.parseLocalDate(date).toDateMidnight();
    }
    final List<DiningHall> halls = menuDao.getDiningHalls(d, request);

    if (halls != null && halls.size() == 1) {
        return showDiningHallView(request, halls.get(0).getKey(), paramFormat.print(d));
    }

    else {
        mav.addObject("diningHalls", menuDao.getDiningHalls(d, request));
        mav.addObject("displayDate", displayFormat.print(d));
        mav.addObject("date", paramFormat.print(d));
        mav.addObject("prev", paramFormat.print(d.minusDays(1)));
        mav.addObject("next", paramFormat.print(d.plusDays(1)));
        return mav;
    }

}

From source file:org.jasig.portlet.campuslife.dining.mvc.portlet.MainController.java

License:Apache License

@RenderMapping(params = "action=diningHall")
public ModelAndView showDiningHallView(final RenderRequest request, final String diningHall,
        final String date) {

    // determine if the request represents a mobile browser and set the
    // view name accordingly
    final boolean isMobile = viewSelector.isMobile(request);
    final String viewName = isMobile ? "diningHall-jQM" : "diningHall";
    final ModelAndView mav = new ModelAndView("dining/".concat(viewName));

    if (logger.isDebugEnabled()) {
        logger.debug("Using view name " + viewName + " for dining hall view");
    }//from   w w w  .j  a va 2s.c  o  m

    final DateMidnight d = paramFormat.parseLocalDate(date).toDateMidnight();
    final DiningHall dh = menuDao.getDiningHall(d, diningHall);
    mav.addObject("diningHall", dh);

    if (dh.getLocationCode() != null) {
        final String url = urlService.getLocationUrl(dh.getLocationCode(), request);
        mav.addObject("locationUrl", url);
    }

    final List<DiningHall> halls = menuDao.getDiningHalls(d, request);
    mav.addObject("hasMultipleLocations", halls.size() > 1);
    mav.addObject("date", paramFormat.print(d));
    mav.addObject("prev", paramFormat.print(d.minusDays(1)));
    mav.addObject("next", paramFormat.print(d.plusDays(1)));
    mav.addObject("displayDate", displayFormat.print(d));

    return mav;

}

From source file:org.key2gym.client.dialogs.EditClientDialog.java

License:Apache License

private void reloadPurchasesTab() {
    /*/*from  w  ww .  jav a2 s .  c  o  m*/
     * Purchases tab
     */
    List<OrderDTO> ordersDTO;
    DateMidnight end = new DateMidnight();
    DateMidnight begin;
    if (purchasesFilterComboBox.getSelectedIndex() == 0) {
        begin = end.minusDays(7);
    } else if (purchasesFilterComboBox.getSelectedIndex() == 1) {
        begin = end.minusMonths(1);
    } else if (purchasesFilterComboBox.getSelectedIndex() == 2) {
        begin = end.minusMonths(3);
    } else {
        begin = client.getRegistrationDate();
    }

    try {
        ordersDTO = ordersService.findForClientWithinPeriod(clientId, begin, end);
    } catch (ValidationException | SecurityViolationException ex) {
        throw new RuntimeException(ex);
    }

    DefaultMutableTreeNode topNode = new DefaultMutableTreeNode();
    DefaultMutableTreeNode dateNode;
    DefaultMutableTreeNode itemNode;
    for (OrderDTO orderDTO : ordersDTO) {
        String text = MessageFormat.format(getString("Text.Order.withDateAndTotalAndPaid"),
                new Object[] { orderDTO.getDate().toDate(), //NOI18N
                        orderDTO.getTotal().toPlainString(), orderDTO.getPayment().toPlainString() });
        dateNode = new DefaultMutableTreeNode(text);

        for (OrderLineDTO orderLine : orderDTO.getOrderLines()) {
            String nodeText = MessageFormat.format(
                    getString("Text.OrderLine(ItemTitle,Quantity,DiscountTitle)"),
                    new Object[] { orderLine.getItemTitle(), orderLine.getQuantity(),
                            orderLine.getDiscountTitle() == null ? getString("Text.None")
                                    : orderLine.getDiscountTitle() });
            itemNode = new DefaultMutableTreeNode(nodeText);
            dateNode.add(itemNode);
        }

        topNode.add(dateNode);
    }

    purchasesTree.setModel(new DefaultTreeModel(topNode));
}

From source file:org.key2gym.client.dialogs.ManageFreezesDialog.java

License:Apache License

private void updateGUI() {
    List<FreezeDTO> freezes;
    DateMidnight today = new DateMidnight();
    try {//from  w w  w  .  j  av a2 s  .c om
        if (periodsComboBox.getSelectedIndex() == 0) {
            freezes = freezesService.findByDateIssuedRange(today.minusDays(7), today);
        } else if (periodsComboBox.getSelectedIndex() == 1) {
            freezes = freezesService.findByDateIssuedRange(today.minusMonths(1), today);
        } else if (periodsComboBox.getSelectedIndex() == 2) {
            freezes = freezesService.findByDateIssuedRange(today.minusMonths(3), today);
        } else {
            freezes = freezesService.findAll();
        }
    } catch (UserException ex) {
        UserExceptionHandler.getInstance().processException(ex);
        return;
    }

    freezesTableModel.setFreezes(freezes);
}

From source file:org.key2gym.client.dialogs.PickDateDialog.java

License:Apache License

/**
 * Initializes the dialog's components./*from www . j a  va2s.  c  o  m*/
 */
private void initComponents() {

    dateLabel = new JLabel(getString("Label.Date"));

    dateComboBox = new JComboBox();
    dateComboBox.setEditable(true);
    DateMidnight startDate = new DateMidnight();
    String[] dates = new String[10];
    for (int i = 0; i < 10; i++) {
        dates[i] = startDate.toString("dd-MM-yyyy");
        startDate = startDate.minusDays(1);
    }
    dateComboBox.setModel(new DefaultComboBoxModel(dates));

    okButton = new JButton(getOkAction());
    cancelButton = new JButton(getCancelAction());

    okButton.setPreferredSize(cancelButton.getPreferredSize());

    getRootPane().setDefaultButton(okButton);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(getString("Title.PickDate")); // NOI18N        
}

From source file:ru.org.linux.tag.TagPageController.java

License:Apache License

private static ImmutableListMultimap<String, Topic> datePartition(Iterable<Topic> topics,
        final Function<Topic, DateTime> dateExtractor) {
    final DateMidnight startOfToday = new DateMidnight();
    final DateMidnight startOfYesterday = startOfToday.minusDays(1);
    final DateMidnight startOfYear = startOfToday.withDayOfYear(1);

    return Multimaps.index(topics, new Function<Topic, String>() {
        @Override//from  ww  w .  ja  va  2  s .c o  m
        public String apply(Topic input) {
            DateTime date = dateExtractor.apply(input);

            if (date.isAfter(startOfToday)) {
                return "?";
            } else if (date.isAfter(startOfYesterday)) {
                return "";
            } else if (date.isAfter(startOfYear)) {
                return THIS_YEAR_FORMAT.print(date);
            } else {
                return OLD_YEAR_FORMAT.print(date);
            }
        }
    });
}

From source file:se.streamsource.streamflow.client.ui.workspace.table.PerspectivePeriodModel.java

License:Apache License

private String getSearchPeriod(Date fromDate, int direction, String periodName, String datePattern,
        String separator) {/*from  w ww  .j ava  2 s. c  o m*/
    DateMidnight from = new DateMidnight(fromDate);
    DateMidnight to = null;
    DateTimeFormatter format = DateTimeFormat.forPattern(datePattern);

    switch (Period.valueOf(periodName)) {
    case one_day:
        return format.print(from);

    case three_days:
        to = (direction == 1) ? from.plusDays(2) : from.minusDays(2);
        break;

    case one_week:
        to = (direction == 1) ? from.plusWeeks(1).minusDays(1) : from.minusWeeks(1).plusDays(1);
        break;

    case two_weeks:
        to = (direction == 1) ? from.plusWeeks(2).minusDays(1) : from.minusWeeks(2).plusDays(1);
        break;

    case one_month:
        to = (direction == 1) ? from.plusMonths(1).minusDays(1) : from.minusMonths(1).plusDays(1);
        break;

    case six_months:
        to = (direction == 1) ? from.plusMonths(6).minusDays(1) : from.minusMonths(6).plusDays(1);
        break;

    case one_year:
        to = (direction == 1) ? from.plusYears(1).minusDays(1) : from.minusYears(1).plusDays(1);
        break;

    }
    return (direction == 1) ? format.print(from) + separator + format.print(to)
            : format.print(to) + separator + format.print(from);

}