org.joda.time.LocalDate.minusYears()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.joda.time.LocalDate.minusYears()方法的一些代码示例,展示了LocalDate.minusYears()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.minusYears()方法的具体详情如下:
包路径:org.joda.time.LocalDate
类名称:LocalDate
方法名:minusYears

LocalDate.minusYears介绍

[英]Returns a copy of this date minus the specified number of years.

This subtracts the specified number of years from the date. If subtracting years makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

LocalDate subtracted = dt.minusYears(6); 
LocalDate subtracted = dt.minus(Period.years(6)); 
LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);

[中]返回此日期减去指定年数的副本。
这将从日期中减去指定的年数。如果减去年份使月日无效,则调整为该月的最后一个有效日。此LocalDate实例是不可变的,不受此方法调用的影响。
以下三行实际上是相同的:

LocalDate subtracted = dt.minusYears(6); 
LocalDate subtracted = dt.minus(Period.years(6)); 
LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);

代码示例

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCreateWithRequestedDate() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final LocalDate requestedDate = init.minusYears(1);
  final String productName = "Shotgun";
  final BillingPeriod term = BillingPeriod.MONTHLY;
  final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
  testListener.pushExpectedEvent(NextEvent.PHASE);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate);
  assertNotNull(subscription);
  //
  // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates.
  // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later.
  //
  final List<SubscriptionBaseEvent> events = subscription.getEvents();
  Assert.assertEquals(events.size(), 2);
  final SubscriptionBaseEvent trialEvent = events.get(0);
  final SubscriptionBaseEvent phaseEvent = events.get(1);
  assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey());
  assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0);
  assertListenerStatus();
  final SubscriptionBaseTransition transition = subscription.getPreviousTransition();
  assertEquals(transition.getPreviousEventId(), trialEvent.getId());
  assertEquals(transition.getNextEventId(), phaseEvent.getId());
  assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0);
  assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0);
}

代码示例来源:origin: killbill/killbill

@Test(groups = "slow")
public void testCreateBundlesWithSameExternalKeys() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final LocalDate requestedDate = init.minusYears(1);

代码示例来源:origin: org.schoellerfamily.gedbrowser/gedbrowser-analytics

/**
 * Decrement the date by a number of years.
 *
 * @param date the input date
 * @param years the number of years
 * @return new date
 */
protected final LocalDate minusYears(final LocalDate date,
    final int years) {
  return date.minusYears(years);
}

代码示例来源:origin: nl.cloudfarming.client/calendar-api

public static LocalDate previousYear(LocalDate actual) { 
  return actual.minusYears(1);
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * get$dateOfLastYear
 *
 * @return a {@link java.util.Date} object.
 */
public Date get$dateOfLastYear(){
  LocalDate dt = new LocalDate();
  return dt.minusYears(1).toDate();
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * getDateOfLastYear
 *
 * @return a {@link java.lang.String} object.
 */
public String getDateOfLastYear(){
  LocalDate dt = new LocalDate();
  return dt.minusYears(1).toString("yyyy-MM-dd");
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * getPreYear
 *
 * @return a int.
 */
public int getPreYear(){
  LocalDate dt = new LocalDate();
  return dt.minusYears(1).getYear();
}

代码示例来源:origin: com.atlassian.jira/jira-api

public LocalDate minusYears(int years)
{
  return new LocalDate(toJodaLocalDate().minusYears(years));
}

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

private BigDecimal getAccrualCategoryBalance(String principalId, AccrualCategory accrualCategory, LocalDate endDate) {
  BigDecimal accrualCategoryBalance = BigDecimal.ZERO;
  
  LocalDate beginDate = endDate.minusYears(1);
  List<LeaveBlock> leaveBlocks = getLeaveBlockService().getLeaveBlocks(principalId, beginDate, endDate);
  
  for (LeaveBlock leaveBlock : leaveBlocks) {
    if (StringUtils.equals(leaveBlock.getAccrualCategory(), accrualCategory.getAccrualCategory())) {
      if (StringUtils.equals(leaveBlock.getRequestStatus(), HrConstants.REQUEST_STATUS.APPROVED)) {
        accrualCategoryBalance = accrualCategoryBalance.add(leaveBlock.getLeaveAmount());
      }
    }
  }
  
  return accrualCategoryBalance;
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public boolean hasAnyResidencePaymentsInDebtForPreviousYear() {
  final int previousYear = new LocalDate().minusYears(1).getYear();
  for (final Event event : getResidencePaymentEvents()) {
    final ResidenceEvent residenceEvent = (ResidenceEvent) event;
    if (residenceEvent.isFor(previousYear) && !residenceEvent.isCancelled() && !residenceEvent.isPayed()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: fluxtream/fluxtream-app

public void decrementTimespan() {
  switch (timeUnit) {
    case DAY:
      fromDate = fromDate.minusDays(1);
      break;
    case WEEK:
      fromDate = fromDate.minusWeeks(1);
      break;
    case MONTH:
      fromDate = fromDate.minusMonths(1);
      break;
    case YEAR:
      fromDate = fromDate.minusYears(1);
      break;
  }
}

代码示例来源:origin: org.flowable/flowable-dmn-engine

public static Date subtractDate(Object startDate, Object years, Object months, Object days) {
  LocalDate currentDate = new LocalDate(startDate);
  currentDate = currentDate.minusYears(intValue(years));
  currentDate = currentDate.minusMonths(intValue(months));
  currentDate = currentDate.minusDays(intValue(days));
  return currentDate.toDate();
}

代码示例来源:origin: com.ning.billing/killbill-invoice

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
  super.beforeMethod();
  date_migrated = clock.getUTCToday().minusYears(1);
  date_regular = clock.getUTCNow();
  final Account account = invoiceUtil.createAccount(callContext);
  accountId = account.getId();
  migrationInvoiceId = createAndCheckMigrationInvoice(accountId);
  regularInvoiceId = invoiceUtil.generateRegularInvoice(account, date_regular, callContext);
}

代码示例来源:origin: org.kill-bill.billing/killbill-subscription

@Test(groups = "slow")
public void testCreateWithRequestedDate() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final LocalDate requestedDate = init.minusYears(1);
  final String productName = "Shotgun";
  final BillingPeriod term = BillingPeriod.MONTHLY;
  final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
  testListener.pushExpectedEvent(NextEvent.PHASE);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate);
  assertNotNull(subscription);
  //
  // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates.
  // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later.
  //
  final List<SubscriptionBaseEvent> events = subscription.getEvents();
  Assert.assertEquals(events.size(), 2);
  final SubscriptionBaseEvent trialEvent = events.get(0);
  final SubscriptionBaseEvent phaseEvent = events.get(1);
  assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey());
  assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0);
  assertListenerStatus();
  final SubscriptionBaseTransition transition = subscription.getPreviousTransition();
  assertEquals(transition.getPreviousEventId(), trialEvent.getId());
  assertEquals(transition.getNextEventId(), phaseEvent.getId());
  assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0);
  assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0);
}

代码示例来源:origin: org.kill-bill.billing/killbill-invoice

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
  if (hasFailed()) {
    return;
  }
  super.beforeMethod();
  date_migrated = clock.getUTCToday().minusYears(1);
  date_regular = clock.getUTCToday();
  final Account account = invoiceUtil.createAccount(callContext);
  accountId = account.getId();
  migrationInvoiceId = createAndCheckMigrationInvoice(accountId);
  regularInvoiceId = invoiceUtil.generateRegularInvoice(account, date_regular, callContext);
}

代码示例来源:origin: org.kill-bill.billing/killbill-subscription

@Test(groups = "slow")
public void testCreateBundlesWithSameExternalKeys() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final LocalDate requestedDate = init.minusYears(1);

代码示例来源:origin: org.kuali.kpme/kpme-tk-lm-impl

@Override
public void calculateFutureAccrualUsingPlanningMonth(String principalId, LocalDate asOfDate, String runAsPrincipalId) {
  PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService().getPrincipalCalendar(principalId, asOfDate);
  if(phra != null) {
    // use the date from pay period to get the leave plan
    LeavePlanContract lp = HrServiceLocator.getLeavePlanService().getLeavePlan(phra.getLeavePlan(), asOfDate);  
    if(lp != null && StringUtils.isNotEmpty(lp.getPlanningMonths())) {
      // go back a year 
      LocalDate startDate = asOfDate.minusYears(1);
      if(startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
        startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
      }
      // go forward using planning months
      LocalDate endDate = asOfDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()));
      // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
      if(endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
        endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
      }
      runAccrual(principalId, startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), true, runAsPrincipalId);
    }
  }
}

相关文章