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

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

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

LocalDate.plusMonths介绍

[英]Returns a copy of this date plus the specified number of months.

This adds the specified number of months to the date. The addition may change the year, but the day-of-month is normally unchanged. If adding months 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 added = dt.plusMonths(6); 
LocalDate added = dt.plus(Period.months(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6);

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

LocalDate added = dt.plusMonths(6); 
LocalDate added = dt.plus(Period.months(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6);

代码示例

代码示例来源:origin: dlew/joda-time-android

private void sampleLocalDate() {
  List<String> text = new ArrayList<String>();
  LocalDate now = LocalDate.now();
  text.add("Now: " + now);
  text.add("Now + 2 days: " + now.plusDays(2));
  text.add("Now + 3 months: " + now.plusMonths(3));
  addSample("LocalDate", text);
}

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

@Override
public LocalDate addToLocalDate(final LocalDate localDate) {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new IllegalStateException("Unexpected duration unit " + unit);
  }
}

代码示例来源:origin: joda-time/joda-time

} else {
  LocalDate date = (day == -1 ?
      new LocalDate(2001, month, 1).plusMonths(1) :
      new LocalDate(2001, month, day).plusDays(1));
  advance = (day != -1 && dayOfWeek != 0);

代码示例来源:origin: JodaOrg/joda-time

} else {
  LocalDate date = (day == -1 ?
      new LocalDate(2001, month, 1).plusMonths(1) :
      new LocalDate(2001, month, day).plusDays(1));
  advance = (day != -1 && dayOfWeek != 0);

代码示例来源:origin: konsoletyper/teavm

millis = parseTime("23:59:59.999");
} else {
  LocalDate date = day == -1 ? new LocalDate(2001, month, 1).plusMonths(1)
      : new LocalDate(2001, month, day).plusDays(1);
  advance = day != -1 && dayOfWeek != 0;

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

@Override
public LocalDate addToLocalDate(final LocalDate localDate) throws CatalogApiException {
  if ((number == null) && (unit != TimeUnit.UNLIMITED)) {
    return localDate;
  }
  switch (unit) {
    case DAYS:
      return localDate.plusDays(number);
    case WEEKS:
      return localDate.plusWeeks(number);
    case MONTHS:
      return localDate.plusMonths(number);
    case YEARS:
      return localDate.plusYears(number);
    case UNLIMITED:
    default:
      throw new CatalogApiException(ErrorCode.CAT_UNDEFINED_DURATION, unit);
  }
}

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

@VisibleForTesting
DateTime getEffectiveDateForNewBCD(final int bcd, @Nullable final LocalDate effectiveFromDate, final InternalCallContext internalCallContext) {
  if (internalCallContext.getAccountRecordId() == null) {
    throw new IllegalStateException("Need to have a valid context with accountRecordId");
  }
  // Today as seen by this account
  final LocalDate startDate = effectiveFromDate != null ? effectiveFromDate : internalCallContext.toLocalDate(internalCallContext.getCreatedDate());
  // We want to compute a LocalDate in account TZ which maps to the provided 'bcd' and then compute an effectiveDate for when that BCD_CHANGE event needs to be triggered
  //
  // There is a bit of complexity to make sure the date we chose exists (e.g: a BCD of 31 in a february month would not make sense).
  final int currentDay = startDate.getDayOfMonth();
  final int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue();
  final LocalDate requestedDate;
  if (bcd < currentDay) {
    final LocalDate startDatePlusOneMonth = startDate.plusMonths(1);
    final int lastDayOfNextMonth = startDatePlusOneMonth.dayOfMonth().getMaximumValue();
    final int originalBCDORLastDayOfMonth = bcd <= lastDayOfNextMonth ? bcd : lastDayOfNextMonth;
    requestedDate = new LocalDate(startDatePlusOneMonth.getYear(), startDatePlusOneMonth.getMonthOfYear(), originalBCDORLastDayOfMonth);
  } else if (bcd == currentDay && effectiveFromDate == null) {
    // will default to immediate event
    requestedDate = null;
  } else if (bcd <= lastDayOfMonth) {
    requestedDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), bcd);
  } else /* bcd > lastDayOfMonth && bcd > currentDay */ {
    requestedDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), lastDayOfMonth);
  }
  return requestedDate == null ? internalCallContext.getCreatedDate() : internalCallContext.toUTCDateTime(requestedDate);
}

代码示例来源:origin: camunda/camunda-bpm-platform

if (str.equals("24:00")) {
  LocalDate date = (day == -1 ?
      new LocalDate(2001, month, 1).plusMonths(1) :
      new LocalDate(2001, month, day).plusDays(1));
  advance = (day != -1);

代码示例来源:origin: yannecer/NCalendar

@Override
protected LocalDate getDate(LocalDate localDate, int count) {
  LocalDate date = localDate.plusMonths(count);
  return date;
}

代码示例来源:origin: yannecer/NCalendar

@Override
protected BaseCalendarView getView(Context context,int weekFirstDayType,LocalDate initializeDate,int curr,int position) {
  LocalDate date = initializeDate.plusMonths(position - curr);
  MonthView monthView = new MonthView(context, date, weekFirstDayType, mOnClickMonthViewListener);
  return monthView;
}

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

public TreeSet<String> getDatesForMonth(final int year, final int month) {
  LocalDate dayOfMonth = TimeUtils.getBeginningOfMonth(year, month);
  final LocalDate nextMonthStart = dayOfMonth.plusMonths(1);
  TreeSet<String> dates = new TreeSet<String>();
  while(dayOfMonth.isBefore(nextMonthStart)) {
    final String date = TimeUtils.dateFormatterUTC.print(dayOfMonth);
    dates.add(date);
    dayOfMonth = dayOfMonth.plusDays(1);
  }
  return dates;
}

代码示例来源:origin: yannecer/NCalendar

/**
 * 第一个是不是第二个的上一个月,只在此处有效
 *
 * @param date1
 * @param date2
 * @return
 */
public static boolean isLastMonth(LocalDate date1, LocalDate date2) {
  LocalDate date = date2.plusMonths(-1);
  return date1.getMonthOfYear() == date.getMonthOfYear();
}

代码示例来源:origin: yannecer/NCalendar

/**
 * 第一个是不是第二个的下一个月,只在此处有效
 *
 * @param date1
 * @param date2
 * @return
 */
public static boolean isNextMonth(LocalDate date1, LocalDate date2) {
  LocalDate date = date2.plusMonths(1);
  return date1.getMonthOfYear() == date.getMonthOfYear();
}

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

public static BigDecimal calculateProRationAfterLastBillingCycleDate(final LocalDate endDate, final LocalDate previousBillThroughDate,
                                   final BillingPeriod billingPeriod) {
  // Note: assumption is that previousBillThroughDate is correctly aligned with the billing cycle day
  final LocalDate nextBillThroughDate = previousBillThroughDate.plusMonths(billingPeriod.getNumberOfMonths());
  return calculateProrationBetweenDates(previousBillThroughDate, endDate, previousBillThroughDate, nextBillThroughDate);
}

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

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();
}

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

@Test(groups = "fast")
public void testSinglePlan_ExactlyOnePeriodAfterStart() throws InvalidDateSequenceException {
  final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
  final LocalDate targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
  testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

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

@Test(groups = "fast")
public void testSinglePlan_StartingMidFebruaryOfLeapYear() throws InvalidDateSequenceException {
  final LocalDate startDate = invoiceUtil.buildDate(2012, 2, 15);
  final LocalDate targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
  testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

代码示例来源:origin: net.objectlab.kit/datecalc-joda

@Override
public DateCalculator<LocalDate> moveByMonths(final int months) {
  setCurrentIncrement(months);
  setCurrentBusinessDate(getCurrentBusinessDate().plusMonths(months));
  if (getHolidayHandler() != null) {
    setCurrentBusinessDate(getHolidayHandler().moveCurrentDate(this));
  }
  return this;
}

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

@Test(groups = "fast")
public void testSinglePlan_SlightlyMoreThanOnePeriodAfterStart() throws InvalidDateSequenceException {
  final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 15);
  final LocalDate targetDate = startDate.plusMonths(getBillingPeriod().getNumberOfMonths()).plusDays(1);
  testCalculateNumberOfBillingCycles(startDate, targetDate, 15, TWO);
}

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

@Test(groups = "fast")
public void testSinglePlan_CrossingYearBoundary() throws InvalidDateSequenceException {
  final LocalDate startDate = invoiceUtil.buildDate(2011, 12, 15);
  final LocalDate oneCycleLater = startDate.plusMonths(getBillingPeriod().getNumberOfMonths());
  // test just before the billing cycle day
  testCalculateNumberOfBillingCycles(startDate, oneCycleLater.plusDays(-1), 15, ONE);
  // test on the billing cycle day
  testCalculateNumberOfBillingCycles(startDate, oneCycleLater, 15, TWO);
  // test just after the billing cycle day
  testCalculateNumberOfBillingCycles(startDate, oneCycleLater.plusDays(1), 15, TWO);
}

相关文章