List of usage examples for org.joda.time DateMidnight minusMonths
public DateMidnight minusMonths(int months)
From source file:com.atlassian.theplugin.idea.bamboo.tree.DatePeriod.java
License:Apache License
public static DatePeriod getBuilDate(Date aDate) { DateTime date = new DateTime(aDate); DateMidnight midnight = new DateMidnight(); if (date.isAfter(midnight)) { return TODAY; } else if (date.isAfter(midnight.minusDays(1))) { return YESTERDAY; } else if (date.isAfter(midnight.minusDays(DAYS_IN_WEEK))) { return LAST_WEEK; } else if (date.isAfter(midnight.minusMonths(1))) { return LAST_MONTH; } else {//from w w w. j a va2s. c om return OLDER; } }
From source file:com.excilys.ebi.bank.service.impl.BankServiceImpl.java
License:Apache License
@Override public Calendar getCalendar(Integer year, Integer month) { Calendar calendar = new Calendar(); // build months List<DateTime> months = calendar.getMonths(); DateMidnight thisMonth = getDefaultDateTime().toDateMidnight().withDayOfMonth(1); months.add(thisMonth.toDateTime());/*w w w. ja v a 2 s. c o m*/ // display last 6 months while (months.size() < 6) { thisMonth = thisMonth.minusMonths(1); months.add(thisMonth.toDateTime()); } reverse(months); // build selectedMonth if (year != null) { notNull(month, "month is required if year is specified"); DateTime selectedMonth = new DateMidnight().withDayOfMonth(1).withYear(year).withMonthOfYear(month) .toDateTime(); calendar.setSelectedMonth(selectedMonth); } return calendar; }
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/*from w w w. jav a2 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.key2gym.business.services.FreezesServiceBean.java
License:Apache License
@Override public void addFreeze(Integer clientId, Integer days, String note) throws ValidationException, BusinessException, SecurityViolationException { if (clientId == null) { throw new NullPointerException("The clientId is null."); //NOI18N }/*from w w w . j av a2s. c om*/ if (days == null) { throw new NullPointerException("The days is null."); //NOI18N } if (note == null) { throw new NullPointerException("The note is null."); //NOI18N } if (!callerHasAnyRole(SecurityRoles.SENIOR_ADMINISTRATOR, SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } Client client = getEntityManager().find(Client.class, clientId); if (client == null) { throw new ValidationException(getString("Invalid.Client.ID")); } if (client.getExpirationDate().compareTo(new Date()) < 0) { throw new BusinessException(getString("BusinessRule.Client.SubscriptionExpired")); } if (days < 1 || days > 10) { String message = MessageFormat.format( getString("BusinessRule.Freeze.Days.HasToBeWithinRange.withRangeBeginAndRangeEnd"), 1, 10); throw new ValidationException(message); } if (note.trim().isEmpty()) { throw new ValidationException(getString("Invalid.Freeze.Note.CanNotBeEmpty")); } DateMidnight today = new DateMidnight(); List<ClientFreeze> freezes = getEntityManager() .createNamedQuery("ClientFreeze.findByClientAndDateIssuedRange") //NOI18N .setParameter("client", client).setParameter("rangeBegin", today.minusMonths(1).toDate()) //NOI18N .setParameter("rangeEnd", today.toDate()) //NOI18N .getResultList(); if (!freezes.isEmpty()) { throw new BusinessException(getString("BusinessRule.Freeze.ClientHasAlreadyBeenFrozenLastMonth")); } // Rolls the expiration date client.setExpirationDate(new DateMidnight(client.getExpirationDate()).plusDays(days).toDate()); ClientFreeze clientFreeze = new ClientFreeze(); clientFreeze.setDateIssued(new Date()); clientFreeze.setDays(days); clientFreeze.setClient(client); clientFreeze.setAdministrator(getEntityManager().find(Administrator.class, administratorsService.getByUsername(getCallerPrincipal()).getId())); clientFreeze.setNote(note); getEntityManager().persist(clientFreeze); getEntityManager().flush(); }
From source file:org.key2gym.client.dialogs.EditClientDialog.java
License:Apache License
private void reloadPurchasesTab() { /*// w w w .j ava2 s . c om * 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 {//w w w .ja v a 2 s . co m 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: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) {/* w ww . ja va 2 s .co 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); }