List of usage examples for org.joda.time LocalDate minusMonths
public LocalDate minusMonths(int months)
From source file:org.flowable.dmn.engine.impl.el.util.DateUtil.java
License:Apache License
public static Date subtractDate(Object startDate, Object years, Object months, Object days) { LocalDate currentDate = new LocalDate(startDate); currentDate = currentDate.minusYears(intValue(years)); currentDate = currentDate.minusMonths(intValue(months)); currentDate = currentDate.minusDays(intValue(days)); return currentDate.toDate(); }
From source file:org.jasig.portlet.notice.web.util.DateUtility.java
License:Apache License
public static String todayMinusMonths(Integer months, String jodaFormatPattern) { LocalDate date = new LocalDate(); return DateTimeFormat.forPattern(jodaFormatPattern).print(date.minusMonths(months)); }
From source file:org.killbill.billing.invoice.usage.RawUsageOptimizer.java
License:Apache License
@VisibleForTesting LocalDate getOptimizedRawUsageStartDate(final LocalDate firstEventStartDate, final LocalDate targetDate, final Iterable<InvoiceItem> existingUsageItems, final Map<String, Usage> knownUsage) { if (!existingUsageItems.iterator().hasNext()) { return firstEventStartDate; }/* www. j a v a2 s .c o m*/ // Extract all usage billing period known in that catalog final Set<BillingPeriod> knownUsageBillingPeriod = ImmutableSet .copyOf(Iterables.transform(knownUsage.values(), new Function<Usage, BillingPeriod>() { @Nullable @Override public BillingPeriod apply(final Usage input) { return input.getBillingPeriod(); } })); // Make sure all usage items are sorted by endDate final List<InvoiceItem> sortedUsageItems = USAGE_ITEM_ORDERING.sortedCopy(existingUsageItems); // Compute an array with one date per BillingPeriod: // If BillingPeriod is never defined in the catalog (no need to look for items), we initialize its value // such that it cannot be chosen // final LocalDate[] perBillingPeriodMostRecentConsumableInArrearItemEndDate = new LocalDate[BillingPeriod .values().length - 1]; // Exclude the NO_BILLING_PERIOD int idx = 0; for (BillingPeriod bp : BillingPeriod.values()) { if (bp != BillingPeriod.NO_BILLING_PERIOD) { final LocalDate makerDateThanCannotBeChosenAsTheMinOfAllDates = targetDate .plusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths()); perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx++] = (knownUsageBillingPeriod .contains(bp)) ? null : makerDateThanCannotBeChosenAsTheMinOfAllDates; } } final ListIterator<InvoiceItem> iterator = sortedUsageItems.listIterator(sortedUsageItems.size()); while (iterator.hasPrevious()) { final InvoiceItem previous = iterator.previous(); Preconditions.checkState(previous instanceof UsageInvoiceItem); final UsageInvoiceItem item = (UsageInvoiceItem) previous; final Usage usage = knownUsage.get(item.getUsageName()); if (perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod() .ordinal()] == null) { perBillingPeriodMostRecentConsumableInArrearItemEndDate[usage.getBillingPeriod().ordinal()] = item .getEndDate(); if (!containsNullEntries(perBillingPeriodMostRecentConsumableInArrearItemEndDate)) { break; } } } // Extract the min from all the dates LocalDate targetStartDate = null; idx = 0; for (BillingPeriod bp : BillingPeriod.values()) { if (bp != BillingPeriod.NO_BILLING_PERIOD) { final LocalDate tmp = perBillingPeriodMostRecentConsumableInArrearItemEndDate[idx]; final LocalDate targetBillingPeriodDate = tmp != null ? tmp.minusMonths(config.getMaxRawUsagePreviousPeriod() * bp.getNumberOfMonths()) : null; if (targetStartDate == null || (targetBillingPeriodDate != null && targetBillingPeriodDate.compareTo(targetStartDate) < 0)) { targetStartDate = targetBillingPeriodDate; } idx++; } } final LocalDate result = targetStartDate.compareTo(firstEventStartDate) > 0 ? targetStartDate : firstEventStartDate; return result; }
From source file:org.libreplan.web.users.dashboard.MyTasksAreaModel.java
License:Open Source License
@Override @Transactional(readOnly = true)//from w w w . j ava2s . c o m public List<Task> getTasks() { User user = UserUtil.getUserFromSession(); if (!user.isBound()) { return new ArrayList<Task>(); } /* * mvanmiddelkoop jan 2015 - Tasks from <settings> months ago to * <settings> month ahead */ LocalDate myTodayDate = LocalDate.now(); int since = 1; if (user.getResourcesLoadFilterPeriodSince() != null) { since = user.getResourcesLoadFilterPeriodSince(); } int to = 3; if (user.getResourcesLoadFilterPeriodTo() != null) { to = user.getResourcesLoadFilterPeriodTo(); } List<SpecificResourceAllocation> resourceAllocations = resourceAllocationDAO .findSpecificAllocationsRelatedTo(scenarioManager.getCurrent(), UserDashboardUtil.getBoundResourceAsList(user), myTodayDate.minusMonths(since), myTodayDate.plusMonths(to)); List<Task> tasks = new ArrayList<Task>(); for (SpecificResourceAllocation each : resourceAllocations) { Task task = each.getTask(); if (task != null) { forceLoad(task); /* mvanmiddelkoop jan 2015 - show only unfinished tasks */ if (task.getAdvancePercentage().intValue() < 1) { tasks.add(task); } } } /* * mvanmiddelkoop jan 2015 - Sort Ascending instead of Descending * sortTasksDescendingByStartDate(tasks); */ sortTasksAscendingByStartDate(tasks); return tasks; }
From source file:org.medici.bia.controller.WelcomeController.java
License:Open Source License
/** * /*from ww w . j a v a2 s.co m*/ * @return */ @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView setupForm(HttpSession httpSession) { Map<String, Object> model = new HashMap<String, Object>(0); try { String account = null; User user = (User) httpSession.getAttribute("user"); if (user != null) { account = user.getAccount(); } boolean canAccessTeaching = getUserService().canAccessTeachingModule(account); Map<String, List<?>> forumStatistics = getCommunityService() .getForumStatistics(MAX_NUMBER_OF_MOST_RECENT_FORUM_DISCUSSIONS); model.put("forumStatistics", forumStatistics); if (canAccessTeaching) { Map<String, List<?>> teachingForumStatistics = getTeachingService().getTeachingForumStatistics( MAX_NUMBER_OF_MOST_RECENT_COLLABORATIVE_TRANSCRIPTIONS, MAX_NUMBER_OF_MOST_RECENT_COURSE_DISCUSSIONS, 10, account); model.put("teachingForumStatistics", teachingForumStatistics); } LocalDate now = new LocalDate(); now.minusMonths(1).toDateMidnight().toDate(); Map<String, Long> lastLogonDBStatistics = getCommunityService() .getDatabaseStatistics(DateUtils.getLastLogonDate()); model.put("lastLogonDBStatistics", lastLogonDBStatistics); Map<String, String> lastLogonUrls = HtmlUtils.generateAdvancedSearchLinks(DateUtils.getLastLogonDate()); model.put("lastLogonUrls", lastLogonUrls); Map<String, Long> currentWeekDBStatistics = getCommunityService() .getDatabaseStatistics(DateUtils.getFirstDayOfCurrentWeek()); model.put("currentWeekDBStatistics", currentWeekDBStatistics); Map<String, String> currentWeekUrls = HtmlUtils .generateAdvancedSearchLinks(DateUtils.getFirstDayOfCurrentWeek()); model.put("currentWeekUrls", currentWeekUrls); Map<String, Long> currentMonthDBStatistics = getCommunityService() .getDatabaseStatistics(DateUtils.getFirstDayOfCurrentMonth()); model.put("currentMonthDBStatistics", currentMonthDBStatistics); Map<String, String> currentMonthUrls = HtmlUtils .generateAdvancedSearchLinks(DateUtils.getFirstDayOfCurrentMonth()); model.put("currentMonthUrls", currentMonthUrls); } catch (ApplicationThrowable applicationThrowable) { model.put("applicationThrowable", applicationThrowable); return new ModelAndView("error/Welcome", model); } return new ModelAndView("Welcome", model); }
From source file:org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent.java
License:Open Source License
@Override public LocalDate findFirstDateOfPeriodForMatchingDate(LocalDate matchingDate) { LocalDate previousMatchingDate = lastDayOfMonthFor(matchingDate.minusMonths(every)); return previousMatchingDate.plusDays(1); }
From source file:rabbit.data.internal.xml.DataStore.java
License:Apache License
@Override public List<File> getDataFiles(LocalDate start, LocalDate end, IPath location) { // Work out the number of months between the two dates, regardless of the // dateOfMonth of each date: int numMonths = (end.getYear() - start.getYear()) * 12; numMonths += end.getMonthOfYear() - start.getMonthOfYear(); List<File> result = Lists.newLinkedList(); for (; numMonths >= 0; numMonths--) { File f = getDataFile(end.minusMonths(numMonths), location); if (f.exists()) { result.add(f);/*from w ww . j a v a 2 s . c o m*/ } } return result; }