List of usage examples for org.joda.time LocalDate compareTo
public int compareTo(ReadablePartial partial)
From source file:org.alexlg.bankit.services.SyncService.java
License:Open Source License
/** * This function take all the costs between * the last execution to create the associated * operations in the operation list./*w w w . ja v a 2s. c o m*/ * It runs every day at midnight and 5 seconds */ @Transactional @Scheduled(cron = "5 0 0 * * *") public void materializeCostsIntoOperation() { logger.info("Starting materializeCostsIntoOperation"); //materialize operations 2 days beyond current date LocalDate endDate = getEndSyncDate().plusDays(2); Date startSync = optionsService.getDate(COST_SYNC_OPT); if (startSync == null) { optionsService.set(COST_SYNC_OPT, endDate.toDate()); return; } LocalDate startDate = new LocalDate(startSync); //retrieve costs list List<Cost> costs = null; int nbMonth = 1; if (endDate.getYear() == startDate.getYear() && endDate.getMonthOfYear() == startDate.getMonthOfYear()) { //only retrieve the costs between this 2 "days" costs = costDao.getList(startDate.getDayOfMonth(), endDate.getDayOfMonth()); } else { //getting all costs costs = costDao.getList(); //we generate a least for the current month (as nbMonth = 1) //then we add whole months between start and end. nbMonth += Months.monthsBetween(startDate, endDate).getMonths(); //as monthsBetween calculate for whole month, if start is for example the 24-09 //and the end is the 02-10, monthsBetween will return 0 but we need to have //2 loops, one for september and one for november so we add a month. if (endDate.getDayOfMonth() <= startDate.getDayOfMonth()) { nbMonth++; } } //going through each month and each cost to create the operation for (int m = 0; m < nbMonth; m++) { LocalDate curMonth = startDate.plusMonths(m); int lastDayOfMonth = curMonth.dayOfMonth().getMaximumValue(); for (Cost cost : costs) { int costDay = cost.getDay(); //if the operation is planned after the last day of month //set it to the last day if (costDay > lastDayOfMonth) costDay = lastDayOfMonth; //creating operation date LocalDate opDate = new LocalDate(curMonth.getYear(), curMonth.getMonthOfYear(), costDay); //check if date is in the date interval before creating op if (opDate.isAfter(startDate) && opDate.compareTo(endDate) <= 0) { Operation op = new Operation(); op.setOperationDate(opDate.toDate()); op.setLabel(cost.getLabel()); op.setPlanned(cost.getAmount()); op.setCategory(cost.getCategory()); operationDao.save(op); } } } optionsService.set(COST_SYNC_OPT, endDate.toDate()); }
From source file:org.egov.works.abstractestimate.entity.OverheadValue.java
License:Open Source License
public boolean isWithin(final Period period, final Date dateTime) { final LocalDate start = new LocalDate(period.getStartDate()); final LocalDate end = new LocalDate(period.getEndDate()); final LocalDate date = new LocalDate(dateTime); if (period.getEndDate() == null) return start.compareTo(date) <= 0; else/*from w w w . java 2 s.c o m*/ return start.compareTo(date) <= 0 && end.compareTo(date) >= 0; }
From source file:org.egov.works.models.masters.ScheduleOfRate.java
License:Open Source License
public boolean isWithin(final Period period, final Date dateTime) { final LocalDate start = new LocalDate(period.getStartDate()); LocalDate end = null;//from www . j a va 2 s. c om if (period.getEndDate() != null) end = new LocalDate(period.getEndDate()); final LocalDate date = new LocalDate(dateTime); if (end == null) return start.compareTo(date) <= 0; else return start.compareTo(date) <= 0 && end.compareTo(date) >= 0; // return (end!=null)? start.compareTo(date)<=0 && // end.compareTo(date)>=0 : start.compareTo(date)<=0; }
From source file:org.estatio.dom.lease.breaks.FixedBreakOption.java
License:Apache License
public String validateUpdateReminderDate(final LocalDate reminderDate) { if (reminderDate == null) { return null; }// ww w .j a va 2 s . c om return reminderDate.compareTo(getExerciseDate()) >= 0 ? "Reminder must be before exercise date" : null; }
From source file:org.estatio.dom.lease.breaks.RollingBreakOption.java
License:Apache License
private static LocalDate laterOf(final LocalDate d1, final LocalDate d2) { return d1.compareTo(d2) < 0 ? d1 : d2; }
From source file:org.estatio.dom.lease.InvoicingFrequency.java
License:Apache License
public List<InvoicingInterval> intervalsInDueDateRange(final LocalDate periodStartDate, final LocalDate periodEndDate) { List<InvoicingInterval> invoicingIntervals = new ArrayList<InvoicingInterval>(); if (periodEndDate.compareTo(periodStartDate) > 0) { for (Interval interval : CalendarUtils.intervalsInRange(periodStartDate, periodEndDate, this.rrule)) { LocalDate dueDate = dueDateOfInterval(interval); if (dueDate.compareTo(periodEndDate) < 0) { invoicingIntervals.add(new InvoicingInterval(interval, dueDate)); }//from w ww.ja va 2s . com } } return invoicingIntervals; }
From source file:org.estatio.dom.lease.InvoicingFrequency.java
License:Apache License
public List<InvoicingInterval> intervalsInDueDateRange(final LocalDateInterval rangeInterval, final LocalDateInterval sourceInterval) { List<InvoicingInterval> invoicingIntervals = new ArrayList<InvoicingInterval>(); if (rrule == null) { LocalDate dueDateOfSourceInterval = dueDateOfInterval(sourceInterval); if (rangeInterval.contains(dueDateOfSourceInterval)) { invoicingIntervals.add(new InvoicingInterval(sourceInterval, dueDateOfSourceInterval)); }/*from w w w. ja v a 2 s.c om*/ } else { for (Interval interval : CalendarUtils.intervalsInRange(rangeInterval.startDate(), rangeInterval.endDateExcluding(), this.rrule)) { LocalDate dueDate = dueDateOfInterval(interval); if (dueDate.compareTo(rangeInterval.endDateExcluding()) < 0) { invoicingIntervals.add(new InvoicingInterval(interval, dueDate)); } } } return invoicingIntervals; }
From source file:org.estatio.dom.lease.LeaseTerm.java
License:Apache License
@Action(semantics = SemanticsOf.IDEMPOTENT) public LeaseTerm verifyUntil(final LocalDate date) { LeaseTerm nextTerm = getNext();//from w w w .j a v a 2 s. c o m boolean autoCreateTerms = getLeaseItem().getType().autoCreateTerms(); if (autoCreateTerms) { // Remove items after the period LocalDateInterval effectiveInterval = getLeaseItem().getEffectiveInterval(); LocalDate endDateExcluding = effectiveInterval != null ? effectiveInterval.endDateExcluding() : date; if (getNext() != null && endDateExcluding != null && getNext().getStartDate().compareTo(endDateExcluding) >= 0) { getNext().doRemove(); return this; } } align(); if (autoCreateTerms) { // convenience code to automatically create terms but not for terms // who have a start date after today LocalDateInterval effectiveInterval = getLeaseItem().getEffectiveInterval(); LocalDate minDate = ObjectUtils .min(effectiveInterval == null ? null : effectiveInterval.endDateExcluding(), date); LocalDate nextStartDate = nextStartDate(); if (nextTerm == null && nextStartDate.compareTo(minDate) < 0) { LocalDate nextstartDate = default0CreateNext(null, null); LocalDate nextEndDate = default1CreateNext(null, null); nextTerm = createNext(nextstartDate, nextEndDate); } } if (nextTerm != null) { nextTerm.verifyUntil(date); } return this; }
From source file:org.estatio.dom.lease.LeaseTermForIndexable.java
License:Apache License
@Override @Programmatic//from w w w . j a v a 2 s . c o m public BigDecimal valueForDate(final LocalDate dueDate) { // use the indexed value on or after the effective date, use the base // otherwise if (getEffectiveDate() == null || dueDate.compareTo(getEffectiveDate()) >= 0) { return MathUtils.firstNonZero(getSettledValue(), getIndexedValue(), getBaseValue()); } return MathUtils.firstNonZero(getBaseValue(), getSettledValue()); }
From source file:org.estatio.dom.lease.LeaseTermForServiceCharge.java
License:Apache License
@Override @Programmatic/*w w w.ja v a2 s.co m*/ public BigDecimal valueForDate(final LocalDate dueDate) { // TODO: we might need an effective date on the Service Charge too LocalDate endDate = getInterval().endDateExcluding(); if (endDate != null) { LocalDate effectiveDate = endDate; if (getEndDate() != null && effectiveDate.compareTo(dueDate) <= 0) { return MathUtils.firstNonZero(getAuditedValue(), getBudgetedValue()); } } return getBudgetedValue(); }