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

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

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

LocalDate.plusDays介绍

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

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

LocalDate added = dt.plusDays(6); 
LocalDate added = dt.plus(Period.days(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.days(), 6);

[中]返回此日期加上指定天数的副本。
此LocalDate实例是不可变的,不受此方法调用的影响。
以下三行实际上是相同的:

LocalDate added = dt.plusDays(6); 
LocalDate added = dt.plus(Period.days(6)); 
LocalDate added = dt.withFieldAdded(DurationFieldType.days(), 6);

代码示例

代码示例来源:origin: apache/avro

@Override
public LocalDate fromInt(Integer daysFromEpoch, Schema schema, LogicalType type) {
 return EPOCH_DATE.plusDays(daysFromEpoch);
}

代码示例来源:origin: org.apache.avro/avro

@Override
public LocalDate fromInt(Integer daysFromEpoch, Schema schema, LogicalType type) {
 return EPOCH_DATE.plusDays(daysFromEpoch);
}

代码示例来源: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: dlew/joda-time-android

private void sampleIsToday() {
  List<String> text = new ArrayList<String>();
  LocalDate today = LocalDate.now();
  text.add("Today: " + DateUtils.isToday(today));
  text.add("Tomorrow: " + DateUtils.isToday(today.plusDays(1)));
  text.add("Yesterday: " + DateUtils.isToday(today.minusDays(1)));
  addSample("DateUtils.isToday()", 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

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

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

/**
 * Converts this object to an Interval representing the whole day.
 * <p>
 * The interval may have more or less than 24 hours if this is a daylight
 * savings cutover date.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param zone  the zone to get the Interval in, null means default
 * @return a interval over the day
 */
public Interval toInterval(DateTimeZone zone) {
  zone = DateTimeUtils.getZone(zone);
  DateTime start = toDateTimeAtStartOfDay(zone);
  DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone);
  return new Interval(start, end);
}

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

public BillingStateCalculator createBSCalc() {
  now = new LocalDate();
  final Collection<Invoice> invoices = new ArrayList<Invoice>();
  invoices.add(createInvoice(now, BigDecimal.ZERO, null));
  invoices.add(createInvoice(now.plusDays(1), BigDecimal.TEN, null));
  invoices.add(createInvoice(now.plusDays(2), new BigDecimal("100.0"), null));
  Mockito.when(invoiceApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices);
  return new BillingStateCalculator(invoiceApi, clock, tagInternalApi) {
    @Override
    public BillingState calculateBillingState(final ImmutableAccountData overdueable,
                         final InternalCallContext context) {
      return null;
    }
  };
}

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

/**
 * Converts this object to an Interval representing the whole day.
 * <p>
 * The interval may have more or less than 24 hours if this is a daylight
 * savings cutover date.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param zone  the zone to get the Interval in, null means default
 * @return a interval over the day
 */
public Interval toInterval(DateTimeZone zone) {
  zone = DateTimeUtils.getZone(zone);
  DateTime start = toDateTimeAtStartOfDay(zone);
  DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone);
  return new Interval(start, end);
}

代码示例来源: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

@Test(groups = "slow")
public void testDuplicateRecords() {
  final UUID subscriptionId = UUID.randomUUID();
  final String unitType1 = "foo";
  final String unitType2 = "bar";
  final LocalDate startDate = new LocalDate(2013, 1, 1);
  final LocalDate endDate = new LocalDate(2013, 2, 1);
  final Long amount1 = 10L;
  final Long amount2 = 5L;
  final Long amount3 = 13L;
  RolledUpUsageModelDao usage1 = new RolledUpUsageModelDao(subscriptionId, unitType1, startDate, amount1, UUID.randomUUID().toString());
  RolledUpUsageModelDao usage2 = new RolledUpUsageModelDao(subscriptionId, unitType1, startDate.plusDays(1), amount2, UUID.randomUUID().toString());
  RolledUpUsageModelDao usage3 = new RolledUpUsageModelDao(subscriptionId, unitType2, endDate.minusDays(1), amount3, UUID.randomUUID().toString());
  List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
  usages.add(usage1);
  usages.add(usage2);
  usages.add(usage3);
  rolledUpUsageDao.record(usages, internalCallContext);
  final List<RolledUpUsageModelDao> result = rolledUpUsageDao.getAllUsageForSubscription(subscriptionId, startDate, endDate, internalCallContext);
  assertEquals(result.size(), 3);
  try {
    rolledUpUsageDao.record(usages, internalCallContext);
    fail("duplicate records accepted");
  } catch (UnableToExecuteStatementException e) {
    assertEquals(result.size(), 3);
  }
}

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

@Test(groups = "slow")
  public void testRecordsWithTrackingIdExist() {
    final UUID subscriptionId = UUIDs.randomUUID();
    final String unitType1 = "foo";
    final String unitType2 = "bar";
    final LocalDate startDate = new LocalDate(2013, 1, 1);
    final LocalDate endDate = new LocalDate(2013, 2, 1);
    final Long amount1 = 10L;
    final Long amount2 = 5L;
    final Long amount3 = 13L;

    String trackingId = UUIDs.randomUUID().toString();

    RolledUpUsageModelDao usage1 = new RolledUpUsageModelDao(subscriptionId, unitType1, startDate, amount1, trackingId);
    RolledUpUsageModelDao usage2 = new RolledUpUsageModelDao(subscriptionId, unitType1, startDate.plusDays(1), amount2, trackingId);
    RolledUpUsageModelDao usage3 = new RolledUpUsageModelDao(subscriptionId, unitType2, endDate.minusDays(1), amount3, UUID.randomUUID().toString());

    List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
    usages.add(usage1);
    usages.add(usage2);
    usages.add(usage3);
    rolledUpUsageDao.record(usages, internalCallContext);

    assertEquals(rolledUpUsageDao.recordsWithTrackingIdExist(subscriptionId, trackingId, internalCallContext),
           Boolean.TRUE);
  }
}

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

RolledUpUsageModelDao usage2 = new RolledUpUsageModelDao(subscriptionId, unitType1, startDate.plusDays(1), amount2, UUID.randomUUID().toString());
RolledUpUsageModelDao usage3 = new RolledUpUsageModelDao(subscriptionId, unitType2, endDate.minusDays(1), amount3, UUID.randomUUID().toString());
List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
assertEquals(result.get(0).getAmount().compareTo(amount1), 0);
assertEquals(result.get(1).getSubscriptionId(), subscriptionId);
assertEquals(result.get(1).getRecordDate().compareTo(startDate.plusDays(1)), 0);
assertEquals(result.get(1).getUnitType(), unitType1);
assertEquals(result.get(1).getAmount().compareTo(amount2), 0);

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

@Test(groups = "slow")
public void testCreateSubscriptionInTheFuture() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final String productName = "Shotgun";
  final BillingPeriod term = BillingPeriod.MONTHLY;
  final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate futureCreationDate = init.plusDays(10);
  DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, futureCreationDate);
  assertListenerStatus();
  assertNotNull(subscription);
  assertEquals(subscription.getState(), EntitlementState.PENDING);
  testListener.pushExpectedEvent(NextEvent.CREATE);
  clock.addDays(10);
  assertListenerStatus();
  subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription.getState(), EntitlementState.ACTIVE);
}

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

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription3() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

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

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription1() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  // The code will be smart to infer the cancelation date as being the future startDate
  subscription.cancel(callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

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

@Test(groups = "slow")
public void testCancelPlanOnPendingSubscription2() throws SubscriptionBaseApiException {
  final String baseProduct = "Shotgun";
  final BillingPeriod baseTerm = BillingPeriod.MONTHLY;
  final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate startDate = clock.getUTCToday().plusDays(5);
  final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate);
  assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING);
  assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
  try {
    subscription.cancelWithDate(null, callContext);
    fail("Cancel plan should have failed : subscription PENDING");
  } catch (SubscriptionBaseApiException e) {
    assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode());
  }
  try {
    subscription.cancelWithDate(subscription.getStartDate().minusDays(1), callContext);
    fail("Cancel plan should have failed : subscription PENDING");
  } catch (SubscriptionBaseApiException e) {
    assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode());
  }
  subscription.cancelWithDate(subscription.getStartDate(), callContext);
  testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
  clock.addDays(5);
  assertListenerStatus();
  final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
  assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
  assertNull(subscription2.getCurrentPlan());
}

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

@Test(groups = "slow")
public void testCancelUncancelFutureSubscription() throws SubscriptionBaseApiException {
  final LocalDate init = clock.getUTCToday();
  final String productName = "Shotgun";
  final BillingPeriod term = BillingPeriod.MONTHLY;
  final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
  final LocalDate futureCreationDate = init.plusDays(10);
  DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, futureCreationDate);
  assertListenerStatus();
  assertNotNull(subscription);
  assertEquals(subscription.getState(), EntitlementState.PENDING);
  // Cancel / Uncancel a few times to make sure this works and we end up on a stable state
  for (int i = 0; i < 3; i++) {
    subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext);
    subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
    assertEquals(subscription.getState(), EntitlementState.PENDING);
    testListener.pushExpectedEvents(NextEvent.UNCANCEL);
    subscription.uncancel(callContext);
    assertListenerStatus();
  }
  // Now check we are on the right state (as if nothing had happened)
  testListener.pushExpectedEvents(NextEvent.CREATE);
  clock.addDays(10);
  assertListenerStatus();
  subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
  assertEquals(subscription.getState(), EntitlementState.ACTIVE);
  testListener.pushExpectedEvent(NextEvent.PHASE);
  clock.addMonths(1);
  assertListenerStatus();
}

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

LocalDate today = LocalDate.now();
LocalDate yesterday = today.minusDays(1);
LocalDate tomorrow = today.plusDays(1);

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

@Test
public void testGetRelativeTimeSpanStringWithPreposition() {
  Context ctx = InstrumentationRegistry.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));
}

相关文章