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

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

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

LocalDate.minusDays介绍

[英]Returns a copy of this date minus 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 subtracted = dt.minusDays(6); 
LocalDate subtracted = dt.minus(Period.days(6)); 
LocalDate subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);

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

LocalDate subtracted = dt.minusDays(6); 
LocalDate subtracted = dt.minus(Period.days(6)); 
LocalDate subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);

代码示例

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

@Test(groups = "fast")
public void testTimeSinceEarliestUnpaidInvoiceEqualsOrExceeds() throws Exception {
  final String xml =
      "<condition>" +
      "	<timeSinceEarliestUnpaidInvoiceEqualsOrExceeds><unit>DAYS</unit><number>10</number></timeSinceEarliestUnpaidInvoiceEqualsOrExceeds>" +
      "</condition>";
  final InputStream is = new ByteArrayInputStream(xml.getBytes());
  final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  final UUID unpaidInvoiceId = UUID.randomUUID();
  final LocalDate now = new LocalDate();
  final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null,
                         unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10),
                         unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20),
                         unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  Assert.assertTrue(!c.evaluate(state0, now));
  Assert.assertTrue(c.evaluate(state1, now));
  Assert.assertTrue(c.evaluate(state2, now));
}

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

@Test(groups = "fast")
public void testResponseForLastFailedPaymentIn() throws Exception {
  final String xml =
      "<condition>" +
      "	<responseForLastFailedPaymentIn><response>INSUFFICIENT_FUNDS</response><response>DO_NOT_HONOR</response></responseForLastFailedPaymentIn>" +
      "</condition>";
  final InputStream is = new ByteArrayInputStream(xml.getBytes());
  final MockCondition c = XMLLoader.getObjectFromStreamNoValidation(is, MockCondition.class);
  final UUID unpaidInvoiceId = UUID.randomUUID();
  final LocalDate now = new LocalDate();
  final BillingState state0 = new BillingState(new UUID(0L, 1L), 0, BigDecimal.ZERO, null,
                         unpaidInvoiceId, PaymentResponse.LOST_OR_STOLEN_CARD, new Tag[]{});
  final BillingState state1 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("100.00"), now.minusDays(10),
                         unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS, new Tag[]{});
  final BillingState state2 = new BillingState(new UUID(0L, 1L), 1, new BigDecimal("200.00"), now.minusDays(20),
                         unpaidInvoiceId, PaymentResponse.DO_NOT_HONOR, new Tag[]{});
  Assert.assertTrue(!c.evaluate(state0, now));
  Assert.assertTrue(c.evaluate(state1, now));
  Assert.assertTrue(c.evaluate(state2, now));
}

代码示例来源: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 testSimple() {
  final UUID subscriptionId = UUID.randomUUID();
  final String unitType = "foo";
  final LocalDate startDate = new LocalDate(2013, 1, 1);
  final LocalDate endDate = new LocalDate(2013, 2, 1);
  final Long amount1 = 10L;
  final Long amount2 = 5L;
  RolledUpUsageModelDao usage1 = new RolledUpUsageModelDao(subscriptionId, unitType, startDate, amount1, UUID.randomUUID().toString());
  RolledUpUsageModelDao usage2 = new RolledUpUsageModelDao(subscriptionId, unitType, endDate.minusDays(1), amount2, UUID.randomUUID().toString());
  List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
  usages.add(usage1);
  usages.add(usage2);
  rolledUpUsageDao.record(usages, internalCallContext);
  final List<RolledUpUsageModelDao> result = rolledUpUsageDao.getUsageForSubscription(subscriptionId, startDate, endDate, unitType, internalCallContext);
  assertEquals(result.size(), 2);
  assertEquals(result.get(0).getSubscriptionId(), subscriptionId);
  assertEquals(result.get(0).getRecordDate().compareTo(startDate), 0);
  assertEquals(result.get(0).getUnitType(), unitType);
  assertEquals(result.get(0).getAmount().compareTo(amount1), 0);
  assertEquals(result.get(1).getSubscriptionId(), subscriptionId);
  assertEquals(result.get(1).getRecordDate().compareTo(endDate.minusDays(1)), 0);
  assertEquals(result.get(1).getUnitType(), unitType);
  assertEquals(result.get(1).getAmount().compareTo(amount2), 0);
}

代码示例来源: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 usage3 = new RolledUpUsageModelDao(subscriptionId, unitType2, endDate.minusDays(1), amount3, UUID.randomUUID().toString());
List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
usages.add(usage1);
assertEquals(result.get(1).getAmount().compareTo(amount2), 0);
assertEquals(result.get(2).getSubscriptionId(), subscriptionId);
assertEquals(result.get(2).getRecordDate().compareTo(endDate.minusDays(1)), 0);
assertEquals(result.get(2).getUnitType(), unitType2);
assertEquals(result.get(2).getAmount().compareTo(amount3), 0);

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

new DescriptiveTag(UUID.randomUUID(), objectType, objectId, clock.getUTCNow())});
final BillingState state1 = new BillingState(objectId, 1, new BigDecimal("100.00"), now.minusDays(10),
                       unpaidInvoiceId, PaymentResponse.INSUFFICIENT_FUNDS,
                       new Tag[]{new DefaultControlTag(ControlTagType.OVERDUE_ENFORCEMENT_OFF, objectType, objectId, clock.getUTCNow())});
final BillingState state2 = new BillingState(objectId, 1, new BigDecimal("200.00"), now.minusDays(20),
                       unpaidInvoiceId,
                       PaymentResponse.DO_NOT_HONOR,

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

@Test(groups = "slow")
  public void testWrapperNoConfig() throws Exception {

    final Account account;
    final OverdueWrapper wrapper;
    final OverdueState state;

    final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
    final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
    state = config.getOverdueStatesAccount().findState(OverdueWrapper.CLEAR_STATE_NAME);
    account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
    wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
    final OverdueState result = wrapper.refresh(clock.getUTCNow(), internalCallContext);

    Assert.assertEquals(result.getName(), state.getName());
    Assert.assertEquals(result.isBlockChanges(), state.isBlockChanges());
    Assert.assertEquals(result.isDisableEntitlementAndChangesBlocked(), state.isDisableEntitlementAndChangesBlocked());
  }
}

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

@Test(groups = "slow")
public void testWrapperBasic() throws Exception {
  final InputStream is = new ByteArrayInputStream(testOverdueHelper.getConfigXml().getBytes());
  final DefaultOverdueConfig config = XMLLoader.getObjectFromStreamNoValidation(is, DefaultOverdueConfig.class);
  ((MockOverdueConfigCache) overdueConfigCache).loadOverwriteDefaultOverdueConfig(config);
  Account account;
  OverdueWrapper wrapper;
  OverdueState state;
  state = config.getOverdueStatesAccount().findState("OD1");
  account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(31));
  wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
  wrapper.refresh(clock.getUTCNow(), internalCallContext);
  testOverdueHelper.checkStateApplied(state);
  state = config.getOverdueStatesAccount().findState("OD2");
  account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(41));
  wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
  wrapper.refresh(clock.getUTCNow(), internalCallContext);
  testOverdueHelper.checkStateApplied(state);
  state = config.getOverdueStatesAccount().findState("OD3");
  account = testOverdueHelper.createAccount(clock.getUTCToday().minusDays(51));
  wrapper = overdueWrapperFactory.createOverdueWrapperFor(account, internalCallContext);
  wrapper.refresh(clock.getUTCNow(), internalCallContext);
  testOverdueHelper.checkStateApplied(state);
}

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

final DryRunArguments dryRunArguments2 = testUtil.createDryRunArguments(subscription.getId(), subscription.getBundleId(), spec, startDate.minusDays(1), SubscriptionEventType.CHANGE, null);
subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), dryRunArguments2, internalCallContext);
fail("Change plan should have failed : subscription PENDING");

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

assertEquals("yesterday", DateUtils.getRelativeTimeSpanString(ctx, LocalDate.now().minusDays(1)));
assertEquals("3 days ago", DateUtils.getRelativeTimeSpanString(ctx, LocalDate.now().minusDays(3)));

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

@Test
public void testIsToday() {
  LocalDate today = LocalDate.now();
  LocalDate yesterday = today.minusDays(1);
  LocalDate tomorrow = today.plusDays(1);

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

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

代码示例来源:origin: org.incode.module.base/incode-module-base-dom

@Override
  public boolean apply(final T ar) {
    return date != null && ar != null && Objects.equal(ar.getEndDate(), date.minusDays(1));
  }
};

代码示例来源:origin: org.motechproject/motech-platform-commons-date

public static int daysPast(LocalDate localDate, DayOfWeek dayOfWeek) {
  int count = 0;
  LocalDate date = localDate;
  while (date.getDayOfWeek() != dayOfWeek.getValue()) {
    date = date.minusDays(1);
    count++;
  }
  return count;
}

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

private void calculateMaxCarryOverForLeavePlan(String documentId, String principalId, CalendarEntry calendarEntry, String leavePlan, LocalDate asOfDate) {
  List<? extends AccrualCategoryContract> accrualCategories = getAccrualCategoryService().getActiveAccrualCategoriesForLeavePlan(leavePlan, asOfDate);
  
  for (AccrualCategoryContract accrualCategory : accrualCategories) {
    BigDecimal adjustmentAmount = getAccrualCategoryCarryOverAdjustment(accrualCategory.getAccrualCategory(), principalId, calendarEntry, asOfDate);
    
    if (adjustmentAmount.compareTo(BigDecimal.ZERO) > 0) {
      LocalDate LeaveDate = calendarEntry.getEndPeriodFullDateTime().toLocalDate().minusDays(1);
    
      addAdjustmentLeaveBlock(documentId, principalId, LeaveDate, accrualCategory, adjustmentAmount.negate());
    }
  }
}

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

public static String toString(Interval interval) {
  final String start = interval.getStart().toLocalDate().toString("yyyy-MM-dd");
  final String end = interval.getEnd().toLocalDate().minusDays(1).toString("yyyy-MM-dd");
  return String.format("[%s,%s]", start, end);
}

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

@Test(groups = "slow")
public void testUserApiAccess() {
  final List<Invoice> byAccount = invoiceUserApi.getInvoicesByAccount(accountId, false, false, callContext);
  Assert.assertEquals(byAccount.size(), 1);
  Assert.assertEquals(byAccount.get(0).getId(), regularInvoiceId);
  final List<Invoice> byAccountAndDate = invoiceUserApi.getInvoicesByAccount(accountId, date_migrated.minusDays(1), false, callContext);
  Assert.assertEquals(byAccountAndDate.size(), 1);
  Assert.assertEquals(byAccountAndDate.get(0).getId(), regularInvoiceId);
  final Collection<Invoice> unpaid = invoiceUserApi.getUnpaidInvoicesByAccountId(accountId, new LocalDate(date_regular.plusDays(1)), callContext);
  Assert.assertEquals(unpaid.size(), 1);
  Assert.assertEquals(unpaid.iterator().next().getId(), regularInvoiceId);
}

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

@Test(groups = "fast")
public void testIsRepareeIncludedInRepair4() throws Exception {
  final LocalDate startDate = new LocalDate(2012, 5, 1);
  final LocalDate startRepair = new LocalDate(2012, 8, 1);
  final LocalDate endDate = new LocalDate(2013, 5, 1);
  // Repaired item
  final InvoiceItem repairedItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, BigDecimal.TEN, BigDecimal.TEN, currency);
  final InvoiceItem repairItem = new RepairAdjInvoiceItem(invoiceId, accountId, startRepair, endDate, BigDecimal.ONE, currency, repairedItem.getId());
  final InvoiceItem invoiceItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startRepair, endDate.minusDays(1), BigDecimal.TEN, BigDecimal.TEN, currency);
  assertTrue(defaultInvoiceGenerator.isRepareeIncludedInRepair(repairItem, repairedItem.getSubscriptionId(), invoiceItem));
}

相关文章