下面列出了org.joda.time.LocalDate#isAfter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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;
}
/**
* 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;
}
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;
}
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);
}
}
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();
}
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;
}
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);
}
}
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;
}
@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;
}
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;
}
@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));
}
public void produceEmptyTurnoversForPeriod(final LocalDate startDate, final LocalDate endDate){
LocalDate date = startDate;
while (!date.isAfter(endDate)){
produceEmptyTurnoversFor(date);
date = date.plusDays(1);
}
}
@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);
}
}
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;
}
@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;
}
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);
}
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;
}
public boolean isAvailable(LocalDate localDate) {
return !localDate.isBefore(mStartDate) && !localDate.isAfter(mEndDate);
}
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;
}