下面列出了org.joda.time.LocalDate#plusYears ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* It's necessary to use the low-level API because the candidate class ({@link PaperclipForInvoice}) and the
* result class ({@link InvoiceForLease}) are different.
*/
@Programmatic
public List<InvoiceForLease> findInvoicesByYearWithSupportingDocuments(final int year) {
final PersistenceManager jdoPersistenceManager = isisJdoSupport.getJdoPersistenceManager();
final Query query = jdoPersistenceManager.newNamedQuery(
PaperclipForInvoice.class,
"findInvoicesByInvoiceDateBetweenWithSupportingDocuments");
query.setResultClass(InvoiceForLease.class);
try {
final LocalDate invoiceDateFrom = new LocalDate(year,1,1);
final LocalDate invoiceDateTo = invoiceDateFrom.plusYears(1);
final List results = (List) query.executeWithMap(ImmutableMap.of(
"invoiceDateFrom", invoiceDateFrom,
"invoiceDateTo", invoiceDateTo
));
return Lists.newArrayList(results);
} finally {
query.closeAll();
}
}
@Override
protected ArrayList<DateHolder> generatePeriod() {
ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
int counter = 0;
checkDate = new LocalDate(cPeriod);
while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusYears(1))) && counter < 10) {
String date = checkDate.year().getAsString();
if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
DateHolder dateHolder = new DateHolder(date, checkDate.toString(), date);
dates.add(dateHolder);
}
checkDate = checkDate.plusYears(1);
counter++;
}
Collections.reverse(dates);
return dates;
}
@Test
public void testGetRelativeTimeSpanStringWithPreposition() {
Context ctx = InstrumentationRegistry.getInstrumentation().getContext();
LocalDate today = LocalDate.now();
LocalDate tomorrow = today.plusDays(1);
LocalDate nextYear = today.plusYears(1);
assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, today, false));
assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, today, true));
assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, false));
assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, true));
assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, false));
assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, true));
DateTime todayDt = DateTime.now();
DateTime tomorrowDt = todayDt.plusDays(1);
DateTime nextYearDt = todayDt.plusYears(1);
assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, false));
assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, true));
assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, false));
assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, true));
assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, false));
assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, true));
}
@Programmatic
@Override
public List<Object> importData(final Object previousRow) {
LeaseItem item = importItem();
LeaseTermForTurnoverRent term = (LeaseTermForTurnoverRent) item.findTerm(termStartDate);
if (term==null) {
if (!item.getTerms().isEmpty()){
LocalDate nextStartDate = item.getTerms().last().getStartDate().plusYears(1);
while (nextStartDate.isBefore(termStartDate)){
LeaseTermForTurnoverRent emptyTerm = (LeaseTermForTurnoverRent) item.newTerm(nextStartDate, null);
emptyTerm.setManualTurnoverRent(BigDecimal.ZERO);
emptyTerm.setStatus(LeaseTermStatus.APPROVED);
nextStartDate = nextStartDate.plusYears(1);
transactionService3.nextTransaction(); // needed because of DN behaviour...
}
}
term = (LeaseTermForTurnoverRent) item.newTerm(termStartDate, null);
}
// always overwrite manual turnover rent and status
term.setManualTurnoverRent(rentNetAmount);
term.setStatus(LeaseTermStatus.APPROVED);
return Lists.newArrayList(term);
}
public YearIterator(int openFP, String[] dataInputPeriods) {
super(dataInputPeriods);
openFuturePeriods = openFP;
cPeriod = new LocalDate(currentDate.getYear(), JAN, 1);
checkDate = new LocalDate(cPeriod);
maxDate = new LocalDate(currentDate.getYear(), JAN, 1);
for (int i = 0; i < openFuturePeriods; i++) {
maxDate = maxDate.plusYears(1);
}
}
public static Date addDate(Date startDate, Integer years, Integer months, Integer days) {
LocalDate currentDate = new LocalDate(startDate);
currentDate = currentDate.plusYears(years);
currentDate = currentDate.plusMonths(months);
currentDate = currentDate.plusDays(days);
return currentDate.toDate();
}
public static Date addDate(Object startDate, Object years, Object months, Object days) {
LocalDate currentDate = new LocalDate(startDate);
currentDate = currentDate.plusYears(intValue(years));
currentDate = currentDate.plusMonths(intValue(months));
currentDate = currentDate.plusDays(intValue(days));
return currentDate.toDate();
}