List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java
License:Apache License
public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final int billingCycleDayLocal) { final int lastDayOfMonth = date.dayOfMonth().getMaximumValue(); final LocalDate fixedDate; if (billingCycleDayLocal > lastDayOfMonth) { fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), lastDayOfMonth, date.getChronology()); } else {/*from www. ja v a 2s . c o m*/ fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), billingCycleDayLocal, date.getChronology()); } LocalDate proposedDate = fixedDate; while (proposedDate.isBefore(date)) { proposedDate = proposedDate.plusMonths(1); } return proposedDate; }
From source file:com.ning.billing.invoice.model.InAdvanceBillingMode.java
License:Apache License
@Override public List<RecurringInvoiceItemData> calculateInvoiceItemData(final LocalDate startDate, @Nullable final LocalDate endDate, final LocalDate targetDate, final int billingCycleDayLocal, final BillingPeriod billingPeriod) throws InvalidDateSequenceException { if (endDate != null && endDate.isBefore(startDate)) { throw new InvalidDateSequenceException(); }//from w ww . ja v a2 s . c om if (targetDate.isBefore(startDate)) { throw new InvalidDateSequenceException(); } final List<RecurringInvoiceItemData> results = new ArrayList<RecurringInvoiceItemData>(); final LocalDate firstBillingCycleDate = calculateBillingCycleDateOnOrAfter(startDate, billingCycleDayLocal); // We are not billing for less than a day (we could...) if (endDate != null && endDate.equals(startDate)) { return results; } // // If there is an endDate and that endDate is before our first coming firstBillingCycleDate, all we have to do // is to charge for that period // if (endDate != null && !endDate.isAfter(firstBillingCycleDate)) { final BigDecimal leadingProRationPeriods = calculateProRationBeforeFirstBillingPeriod(startDate, endDate, billingPeriod); final RecurringInvoiceItemData itemData = new RecurringInvoiceItemData(startDate, endDate, leadingProRationPeriods); results.add(itemData); return results; } // // Leading proration if // i) The first firstBillingCycleDate is strictly after our start date AND // ii) The endDate is is not null and is strictly after our firstBillingCycleDate (previous check) // if (firstBillingCycleDate.isAfter(startDate)) { final BigDecimal leadingProRationPeriods = calculateProRationBeforeFirstBillingPeriod(startDate, firstBillingCycleDate, billingPeriod); if (leadingProRationPeriods != null && leadingProRationPeriods.compareTo(BigDecimal.ZERO) > 0) { // Not common - add info in the logs for debugging purposes final RecurringInvoiceItemData itemData = new RecurringInvoiceItemData(startDate, firstBillingCycleDate, leadingProRationPeriods); log.info("Adding pro-ration: {}", itemData); results.add(itemData); } } // // Calculate the effectiveEndDate from the firstBillingCycleDate: // - If endDate != null and targetDate is after endDate => this is the endDate and will lead to a trailing pro-ration // - If not, this is the last billingCycleDate calculation right after the targetDate // final LocalDate effectiveEndDate; if (endDate != null) { effectiveEndDate = calculateEffectiveEndDate(firstBillingCycleDate, targetDate, endDate, billingPeriod); } else { effectiveEndDate = calculateEffectiveEndDate(firstBillingCycleDate, targetDate, billingPeriod); } // // Based on what we calculated previously, code recompute one more time the numberOfWholeBillingPeriods // final LocalDate lastBillingCycleDate = calculateLastBillingCycleDateBefore(effectiveEndDate, firstBillingCycleDate, billingCycleDayLocal, billingPeriod); final int numberOfWholeBillingPeriods = calculateNumberOfWholeBillingPeriods(firstBillingCycleDate, lastBillingCycleDate, billingPeriod); final int numberOfMonthsPerBillingPeriod = billingPeriod.getNumberOfMonths(); for (int i = 0; i < numberOfWholeBillingPeriods; i++) { final LocalDate servicePeriodStartDate; if (results.size() > 0) { // Make sure the periods align, especially with the pro-ration calculations above servicePeriodStartDate = results.get(results.size() - 1).getEndDate(); } else if (i == 0) { // Use the specified start date servicePeriodStartDate = startDate; } else { throw new IllegalStateException("We should at least have one invoice item!"); } // Make sure to align the end date with the BCD final LocalDate servicePeriodEndDate = firstBillingCycleDate .plusMonths((i + 1) * numberOfMonthsPerBillingPeriod); results.add(new RecurringInvoiceItemData(servicePeriodStartDate, servicePeriodEndDate, BigDecimal.ONE)); } // // Now we check if indeed we need a trailing proration and add that incomplete item // if (effectiveEndDate.isAfter(lastBillingCycleDate)) { final BigDecimal trailingProRationPeriods = calculateProRationAfterLastBillingCycleDate( effectiveEndDate, lastBillingCycleDate, billingPeriod); if (trailingProRationPeriods.compareTo(BigDecimal.ZERO) > 0) { // Not common - add info in the logs for debugging purposes final RecurringInvoiceItemData itemData = new RecurringInvoiceItemData(lastBillingCycleDate, effectiveEndDate, trailingProRationPeriods); log.info("Adding trailing pro-ration: {}", itemData); results.add(itemData); } } return results; }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
/** * Count all non-weekend days in the range. Does not consider holidays! * * @param aStartDate/*from ww w .j av a 2s . c o m*/ * start date * @param aEndDate * end date * @return days not counting Saturdays and Sundays. If start date is after end * date, the value will be negative! If start date equals end date the * return will be 1 if it is a week day. */ public static int getWeekDays(@Nonnull final LocalDate aStartDate, @Nonnull final LocalDate aEndDate) { ValueEnforcer.notNull(aStartDate, "StartDate"); ValueEnforcer.notNull(aEndDate, "EndDate"); final boolean bFlip = aStartDate.isAfter(aEndDate); LocalDate aCurDate = bFlip ? aEndDate : aStartDate; final LocalDate aRealEndDate = bFlip ? aStartDate : aEndDate; int ret = 0; while (!aRealEndDate.isBefore(aCurDate)) { if (!isWeekend(aCurDate)) ret++; aCurDate = aCurDate.plusDays(1); } return bFlip ? -1 * ret : ret; }
From source file:com.redhat.engineering.jenkins.report.plugin.ReportPluginPortlet.java
License:Open Source License
/** * Graph of duration of tests over time. */// w ww . j a v a 2s. co m public Graph getSummaryGraph() { // The standard equals doesn't work because two LocalDate objects can // be differente even if the date is the same (different internal timestamp) Comparator<LocalDate> localDateComparator = new Comparator<LocalDate>() { @Override public int compare(LocalDate d1, LocalDate d2) { if (d1.isEqual(d2)) { return 0; } if (d1.isAfter(d2)) { return 1; } return -1; } }; // We need a custom comparator for LocalDate objects final Map<LocalDate, TestResultAggrSummary> summaries = //new HashMap<LocalDate, TestResultSummary>(); new TreeMap<LocalDate, TestResultAggrSummary>(localDateComparator); LocalDate today = new LocalDate(); // for each job, for each day, add last build of the day to summary for (Job job : getDashboard().getJobs()) { Filter filter = job.getAction(ReportPluginProjectAction.class).getInitializedFilter(); filter.addCombinationFilter(combinationFilter); Run run = job.getFirstBuild(); if (run != null) { // execute only if job has builds LocalDate runDay = new LocalDate(run.getTimestamp()); LocalDate firstDay = (dateRange != 0) ? new LocalDate().minusDays(dateRange) : runDay; while (run != null) { runDay = new LocalDate(run.getTimestamp()); Run nextRun = run.getNextBuild(); if (nextRun != null) { LocalDate nextRunDay = new LocalDate(nextRun.getTimestamp()); // skip run before firstDay, but keep if next build is after start date if (!runDay.isBefore(firstDay) || runDay.isBefore(firstDay) && !nextRunDay.isBefore(firstDay)) { // if next run is not the same day, use this test to summarize if (nextRunDay.isAfter(runDay)) { summarize(summaries, run.getAction(ReportPluginBuildAction.class).getTestResults(), filter, (runDay.isBefore(firstDay) ? firstDay : runDay), nextRunDay.minusDays(1)); } } } else { // use this run's test result from last run to today summarize(summaries, run.getAction(ReportPluginBuildAction.class).getTestResults(), filter, (runDay.isBefore(firstDay) ? firstDay : runDay), today); } run = nextRun; } } } return new Graph(-1, getGraphWidth(), getGraphHeight()) { protected JFreeChart createGraph() { return GraphHelper.createChart(buildDataSet(summaries)); } }; }
From source file:com.stagecents.fnd.api.service.LocationCommandHandler.java
License:Open Source License
/** * Validates that the inactive date is greater than or equal to the session * date. If the inactive date is less than the session date then an * IllegalArgumentException will be raised and processing terminated. * // www . j a v a 2s . com * @param inactiveDate The date the location becomes inactive. * @see Aracle hr_loc_bus */ private void checkInactiveDate(LocalDate inactiveDate) { if (inactiveDate != null) { // TODO Replace today with session date LocalDate today = new LocalDate(); if (inactiveDate.isBefore(today)) { throw new IllegalArgumentException("inactive date cannot be in the past"); } } }
From source file:com.stagecents.fnd.domain.Location.java
License:Open Source License
/** * Validates that the given inactive date is greater than or equal to the * session date. If the inactive date is less than the session date then an * IllegalArgumentException will be raised and processing terminated. * // w w w . ja v a2 s. com * @param inactiveDate The inactive date to test */ private void validateInactiveDate(LocalDate inactiveDate) { if (inactiveDate != null) { LocalDate today = new LocalDate(); if (inactiveDate.isBefore(today)) { throw new IllegalArgumentException("inactive date cannot be in the past"); } } }
From source file:com.stagecents.gl.api.service.CalendarCommandHandler.java
License:Open Source License
/** * Returns true if the given period start and end dates overlap with some * other period that is not an adjustment period. * /* w ww. ja va2 s . c om*/ * @param periods The array of periods that make up the calendar. * @param index The index number of the given period within the array. * @return True if the given period start and end dates overlap with some * other period that is not an adjustment period. */ private boolean overlappingPeriod(PeriodDTO[] periods, int index) { LocalDate startDate = periods[index].getStartDate(); LocalDate endDate = periods[index].getEndDate(); for (int i = 0; i < periods.length; i++) { if (i != index && !(periods[i].isAdjustmentPeriod())) { if (startDate.isBefore(periods[i].getStartDate()) && endDate.isAfter(periods[i].getEndDate())) { return true; } } } return false; }
From source file:com.stagecents.gl.api.service.CalendarCommandHandler.java
License:Open Source License
private LocalDate getYearStartDate(PeriodDTO[] periods) { LocalDate result = new LocalDate(Long.MAX_VALUE); for (int i = 0; i < periods.length; i++) { LocalDate startDate = periods[i].getStartDate(); if (startDate.isBefore(result)) { result = startDate;/*from w w w . j a va 2 s.com*/ } } return result; }
From source file:com.the.todo.Logic.java
License:MIT License
private void sortByDate(Map<DateCategory, List<ToDo>> todoMap, List<ToDo> todoList) { todoMap.clear();//from w w w .j a v a 2 s . c o m Type todoType; LocalDate startDate; LocalDate endDate; LocalDate today = new LocalDate(); LocalDate tomorrow = new LocalDate().plusDays(1); List<ToDo> todoOverdue = new ArrayList<ToDo>(); List<ToDo> todoToday = new ArrayList<ToDo>(); List<ToDo> todoTomorrow = new ArrayList<ToDo>(); List<ToDo> todoUpcoming = new ArrayList<ToDo>(); List<ToDo> todoSomeday = new ArrayList<ToDo>(); for (ToDo todo : todoList) { todoType = todo.getType(); startDate = todo.getStartDate().toLocalDate(); endDate = todo.getEndDate().toLocalDate(); if (todoType == Type.FLOATING) { todoSomeday.add(todo); } if (todoType == Type.DEADLINE) { if (endDate.isBefore(today)) { todoOverdue.add(todo); } else if (endDate.equals(today)) { todoToday.add(todo); } else if (endDate.equals(tomorrow)) { todoTomorrow.add(todo); } } if (todoType == Type.TIMED) { if (endDate.isBefore(today)) { todoOverdue.add(todo); } if (!today.isBefore(startDate) && !today.isAfter(endDate)) { todoToday.add(todo); } if (!tomorrow.isBefore(startDate) && !tomorrow.isAfter(endDate)) { todoTomorrow.add(todo); } } if (displayType == DisplayType.SEARCH) { if (todoType == Type.DEADLINE) { if (endDate.isAfter(tomorrow)) { todoUpcoming.add(todo); } } else if (todoType == Type.TIMED) { if (endDate.isAfter(tomorrow)) { todoUpcoming.add(todo); } } } } if (todoOverdue.size() > 0) { todoMap.put(DateCategory.OVERDUE, todoOverdue); } if (todoToday.size() > 0) { todoMap.put(DateCategory.TODAY, todoToday); } if (todoTomorrow.size() > 0) { todoMap.put(DateCategory.TOMORROW, todoTomorrow); } if (todoUpcoming.size() > 0) { todoMap.put(DateCategory.UPCOMING, todoUpcoming); } if (todoSomeday.size() > 0) { todoMap.put(DateCategory.SOMEDAY, todoSomeday); } for (Entry<DateCategory, List<ToDo>> entry : todoMap.entrySet()) { Collections.sort(entry.getValue()); } }
From source file:com.tomtom.speedtools.apivalidation.ApiValidator.java
License:Apache License
public void checkLocalDate(final boolean required, @Nonnull final String name, @Nullable final String value, @Nonnull final LocalDate minDate, @Nonnull final LocalDate maxDate) { checkNotNull(required, name, value); if (value != null) { try {/* w w w .j av a 2s .c o m*/ final LocalDate localDate = LocalDate.parse(value); // Check range. if (localDate.isBefore(minDate) || localDate.isAfter(maxDate)) { errors.add(new ApiLocalDateOutOfRangeError(name, localDate, minDate, maxDate)); } } catch (final IllegalArgumentException ignored) { errors.add(new ApiLocalDateFormatError(name, value, FORMAT_DATE_ISO)); } } }