Java Code Examples for org.joda.time.LocalDate#isAfter()

The following examples show how to use org.joda.time.LocalDate#isAfter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of IMM dates between 2 dates, it will exclude the start
 * date if it is an IMM date but would include the end date if it is an IMM.
 *
 * @param start
 *            start of the interval, excluded
 * @param end
 *            end of the interval, may be included.
 * @param period
 *            specify when the "next" IMM is, if quarterly then it is the
 *            conventional algorithm.
 * @return list of IMM dates
 */
@Override
public List<LocalDate> getIMMDates(final LocalDate start, final LocalDate end, final IMMPeriod period) {
    final List<LocalDate> dates = new ArrayList<>();

    LocalDate date = start;
    while (true) {
        date = getNextIMMDate(true, date, period);
        if (!date.isAfter(end)) {
            dates.add(date);
        } else {
            break;
        }
    }

    return dates;
}
 
Example 2
Source File: AgreementRole.java    From estatio with Apache License 2.0 6 votes vote down vote up
public String validateAddCommunicationChannel(
        final AgreementRoleCommunicationChannelType type,
        final CommunicationChannel communicationChannel,
        final LocalDate startDate,
        final LocalDate endDate) {
    if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
        return "End date cannot be earlier than start date";
    }
    if (!Sets.filter(getCommunicationChannels(), type.matchingCommunicationChannel()).isEmpty()) {
        return "Add a successor/predecessor from existing communication channel";
    }
    final SortedSet<CommunicationChannel> partyChannels =
            communicationChannelRepository.findByOwner(getParty());
    if (!partyChannels.contains(communicationChannel)) {
        return "Communication channel must be one of those of this party";
    }
    return null;
}
 
Example 3
Source File: InterestRate.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Optional<InterestRateBean> getInterestBean(LocalDate start, LocalDate end, BigDecimal amount) {

        if (end.isAfter(start)) {
            InterestRateBean bean = new InterestRateBean(start, end, amount);
            Interval dueInterval = bean.getInterval();
            for (InterestRate interestRate : Bennu.getInstance().getInterestRateSet()) {
                if (interestRate.isActive(dueInterval)) {
                    Interval overlap = interestRate.getInterval().overlap(dueInterval);
                    bean.addPartial(overlap, interestRate.getValue());
                }
            }
            return Optional.of(bean);
        }

        return Optional.empty();
    }
 
Example 4
Source File: PhdGratuityPaymentPeriod.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Money fine(double fineRate, Money amount, DateTime when) {
    LocalDate whenPaying = new LocalDate(when.getYear(), when.monthOfYear().get(), when.dayOfMonth().get());
    LocalDate lastPaymentDay = new LocalDate(when.getYear(), getMonthLastPayment(), getDayLastPayment());

    if (whenPaying.isAfter(lastPaymentDay)) {
        int monthsOut = when.getMonthOfYear() - lastPaymentDay.getMonthOfYear();

        // if is in the same month, and a day has passed, at least it
        // counts for one month
        if (monthsOut == 0) {
            monthsOut = 1;
        }
        return new Money(amount.getAmount().multiply(new BigDecimal(fineRate * monthsOut)));
    } else {
        return new Money(0);
    }
}
 
Example 5
Source File: FixedAsset.java    From estatio with Apache License 2.0 6 votes vote down vote up
public String validateNewRole(
        final FixedAssetRoleTypeEnum type,
        final Party party,
        final LocalDate startDate,
        final LocalDate endDate) {
    List<FixedAssetRole> currentRoles = fixedAssetRoleRepository.findAllForPropertyAndPartyAndType(this, party, type);
    for (FixedAssetRole fixedAssetRole : currentRoles) {
        LocalDateInterval existingInterval = new LocalDateInterval(fixedAssetRole.getStartDate(), fixedAssetRole.getEndDate());
        LocalDateInterval newInterval = new LocalDateInterval(startDate, endDate);
        if (existingInterval.overlaps(newInterval)) {
            return "The provided dates overlap with a current role of this type and party";
        }
    }

    if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
        return "End date cannot be earlier than start date";
    }

    return null;
}
 
Example 6
Source File: LocalDateCalculator.java    From objectlabkit with Apache License 2.0 6 votes vote down vote up
@Override
public int getNumberOfBusinessDaysBetween(final LocalDate d1, final LocalDate d2) {
    if (d1 == null || d2 == null) {
        return 0;
    }
    final boolean d1B4d2 = !d1.isAfter(d2);
    LocalDate start = d1B4d2 ? d1 : d2;
    LocalDate end = d1B4d2 ? d2 : d1;
    if (getHolidayHandler() != null) {
        start = getHolidayHandler().adjustDate(start, 1, this);
    }

    int count = 0;
    // start = start.plusDays(1);
    while (start.isBefore(end)) {
        if (!isNonWorkingDay(start)) {
            count++;
        }
        start = start.plusDays(1);
    }
    return d1B4d2 ? count : -count;
}
 
Example 7
Source File: TurnoverAggregationService_Test.java    From estatio with Apache License 2.0 6 votes vote down vote up
private List<Turnover> prepareTestTurnovers(final LocalDateInterval interval){
    List<Turnover> result = new ArrayList<>();
    LocalDate date = interval.startDate();
    int cnt = 1;
    while (!date.isAfter(interval.endDate())){
        Turnover t = new Turnover();
        t.setDate(date);
        t.setGrossAmount(BigDecimal.valueOf(cnt));
        t.setNetAmount(BigDecimal.valueOf(cnt).subtract(new BigDecimal("0.50")));
        t.setNonComparable(false);
        t.setPurchaseCount(BigInteger.valueOf(cnt));
        result.add(t);

        date = date.plusMonths(1);
        cnt++;
    }
    return result;
}
 
Example 8
Source File: UnixTimestampRecursiveCopyableDataset.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(Path path) {

  LocalDate endDate = currentTime.toLocalDate();
  LocalDate startDate = endDate.minus(lookbackPeriod);
  Path relativePath = PathUtils.relativizePath(PathUtils.getPathWithoutSchemeAndAuthority(path), datasetRoot());
  Matcher matcher = timestampPattern.matcher(relativePath.toString());
  if (!matcher.matches()) {
    return false;
  }
  Long timestamp = Long.parseLong(matcher.group(1));
  LocalDate dateOfTimestamp = new LocalDateTime(timestamp, dateTimeZone).toLocalDate();
  return !(dateOfTimestamp == null || dateOfTimestamp.isAfter(endDate) || dateOfTimestamp.isEqual(startDate)
      || dateOfTimestamp.isBefore(startDate));
}
 
Example 9
Source File: TurnoverEntryService.java    From estatio with Apache License 2.0 5 votes vote down vote up
public void produceEmptyTurnoversForPeriod(final LocalDate startDate, final LocalDate endDate){
    LocalDate date = startDate;
    while (!date.isAfter(endDate)){
        produceEmptyTurnoversFor(date);
        date = date.plusDays(1);
    }
}
 
Example 10
Source File: LocalDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
@Override
protected void checkBoundary(final LocalDate date) {
    final LocalDate early = getHolidayCalendar().getEarlyBoundary();
    if (early != null && early.isAfter(date)) {
        throw new IndexOutOfBoundsException(date + " is before the early boundary " + early);
    }

    final LocalDate late = getHolidayCalendar().getLateBoundary();
    if (late != null && late.isBefore(date)) {
        throw new IndexOutOfBoundsException(date + " is after the late boundary " + late);
    }
}
 
Example 11
Source File: TurnoverEntryService.java    From estatio with Apache License 2.0 5 votes vote down vote up
public void produceEmptyTurnoversForPropertyAndPeriod(final LocalDate startDate, final LocalDate endDate, final Property property) {
    LocalDate date = startDate;
    while (!date.isAfter(endDate)){
        produceEmptyTurnoversFor(date, property);
        date = date.plusDays(1);
    }
}
 
Example 12
Source File: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private LocalDate calculateIMMMonth(final boolean requestNextIMM, final LocalDate startDate, final int month) {
    int monthOffset;
    LocalDate date = startDate;
    switch (month) {
    case MARCH:
    case JUNE:
    case SEPTEMBER:
    case DECEMBER:
        final LocalDate immDate = calculate3rdWednesday(date);
        if (requestNextIMM && !date.isBefore(immDate)) {
            date = date.plusMonths(MONTHS_IN_QUARTER);
        } else if (!requestNextIMM && !date.isAfter(immDate)) {
            date = date.minusMonths(MONTHS_IN_QUARTER);
        }
        break;

    default:
        if (requestNextIMM) {
            monthOffset = (MONTH_IN_YEAR - month) % MONTHS_IN_QUARTER;
            date = date.plusMonths(monthOffset);
        } else {
            monthOffset = month % MONTHS_IN_QUARTER;
            date = date.minusMonths(monthOffset);
        }
        break;
    }
    return date;
}
 
Example 13
Source File: ProjectRole.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateChangeDates(
		final LocalDate startDate,
		final LocalDate endDate) {
	if(startDate != null && endDate != null && startDate.isAfter(endDate)) {
		return "End date cannot be earlier than start date";
	}
	return null;
}
 
Example 14
Source File: Occupancy_createEmptyTurnovers.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Action()
public Occupancy $$(final LocalDate startDate, final LocalDate endDate) {
    if (!endDate.isBefore(startDate)){
        final List<TurnoverReportingConfig> configs = turnoverReportingConfigRepository.findByOccupancy(occupancy);
        LocalDate date = startDate;
        while (!date.isAfter(endDate)){
            for (TurnoverReportingConfig config : configs){
                config.produceEmptyTurnover(date);
            }
            date = date.plusDays(1);
        }
    }
    return occupancy;
}
 
Example 15
Source File: ConversionUtilities.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
static public LocalDate parseDate(String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }

    if (value.length() < 2) {
        return null;
    }

    LocalDate result = null;
    String normalizedValue = value;

    if (value.length() == "dMMyyyy".length()) {
        normalizedValue = "0".concat(value);
    }

    for (String pattern : CORRECT_DATE_PATTERNS) {
        try {
            result = DateTimeFormat.forPattern(pattern).parseDateTime(normalizedValue).toLocalDate();
        } catch (IllegalArgumentException e) {
            continue;
        }

        if (result.isAfter(DateTimeFormat.forPattern("yyyy").parseDateTime("1920").toLocalDate())
                && result.isBefore(DateTimeFormat.forPattern("yyy").parseDateTime("2020").toLocalDate())) {
            return result;
        }
    }

    throw new IncorrectDateFormatException(value);
}
 
Example 16
Source File: LeaseItem.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public LeaseItem copy(
        final LocalDate startDate,
        final InvoicingFrequency invoicingFrequency,
        final PaymentMethod paymentMethod,
        final Charge charge
) {
    if (!startDate.isAfter(this.getStartDate())) return null; //EST-1899: extra safeguard because corrupts db
    final LeaseItem newItem = getLease().newItem(
            this.getType(), LeaseAgreementRoleTypeEnum.LANDLORD, charge, invoicingFrequency, paymentMethod, startDate);
    this.copyTerms(startDate, newItem);
    this.changeDates(getStartDate(), newItem.getInterval().endDateFromStartDate());
    return newItem;
}
 
Example 17
Source File: LeaseTermForServiceChargeBudgetAuditService.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateMaintainServiceCharges(
        final Property property,
        final List<LeaseItemType> leaseItemTypes,
        final List<LeaseAgreementRoleTypeEnum> invoicedBy,
        final LocalDate startDate,
        final LocalDate endDate) {
    if (startDate.isAfter(endDate)) return "The end date should on or after the start date";
    return null;
}
 
Example 18
Source File: LeaseItem.java    From estatio with Apache License 2.0 5 votes vote down vote up
public String validateCopy(
        final LocalDate startDate,
        final InvoicingFrequency invoicingFrequency,
        final PaymentMethod paymentMethod,
        final Charge charge
) {
    if (!startDate.isAfter(this.getStartDate())) return "The start date of the copy should be after the start date of the current item";
    if (!choices3Copy().contains(charge)) {
        return "Charge (with app tenancy '%s') is not valid for this lease item";
    }
    return null;
}
 
Example 19
Source File: InvoiceSummaryAbstract.java    From estatio with Apache License 2.0 4 votes vote down vote up
public String validateInvoiceAll(final LocalDate invoiceDate, final boolean allowInvoiceDateInFuture) {
    if (invoiceDate.isAfter(clockService.now()) && !allowInvoiceDateInFuture && !getAtPath().startsWith("/ITA")) return "When you want to set the invoice date after today, please check the checkbox";
    return null;
}
 
Example 20
Source File: BaseCalendar.java    From NCalendar with Apache License 2.0 4 votes vote down vote up
public boolean isAvailable(LocalDate localDate) {
    return !localDate.isBefore(mStartDate) && !localDate.isAfter(mEndDate);
}