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

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

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

LocalDate.compareTo介绍

[英]Compares this partial with another returning an integer indicating the order.

The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.

The specified object must be a partial instance whose field types match those of this partial.

NOTE: This implementation violates the Comparable contract. This method will accept any instance of ReadablePartial as input. However, it is possible that some implementations of ReadablePartial exist that do not extend AbstractPartial, and thus will throw a ClassCastException if compared in the opposite direction. The cause of this problem is that ReadablePartial doesn't define the compareTo() method, however we can't change that until v2.0.
[中]将此部分与另一个返回指示顺序的整数的部分进行比较。
字段按从最大到最小的顺序进行比较。第一个不相等的字段用于确定结果。
指定的对象必须是其字段类型与此分部的字段类型匹配的分部实例。
注:此实施违反了可比合同。此方法将接受ReadablePartial的任何实例作为输入。但是,ReadablePartial的某些实现可能不扩展AbstractPartial,因此如果在相反方向进行比较,则会抛出ClassCastException。这个问题的原因是ReadablePartial没有定义compareTo()方法,但是在v2之前我们无法更改它。0

代码示例

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

@Override
  public int compare(final Invoice i1, final Invoice i2) {
    final LocalDate d1 = i1.getInvoiceDate();
    final LocalDate d2 = i2.getInvoiceDate();
    if (d1.compareTo(d2) == 0) {
      return i1.hashCode() - i2.hashCode(); // consistent (arbitrary) resolution for tied dates
    }
    return d1.compareTo(d2);
  }
}

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

/**
 * See {@link android.text.format.DateUtils#isToday} for full docs.
 *
 * @return true if the supplied when is today else false
 */
public static boolean isToday(ReadableInstant time) {
  return LocalDate.now().compareTo(new LocalDate(time)) == 0;
}

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

private DateTime getDryRunEffectiveDate(@Nullable final LocalDate inputDate, final SubscriptionBase subscription, final InternalTenantContext context) {
  if (inputDate == null) {
    return null;
  }
  // We first use context account reference time to get a candidate)
  final DateTime tmp = context.toUTCDateTime(inputDate);
  // If we realize that the candidate is on the same LocalDate boundary as the subscription startDate but a bit prior we correct it to avoid weird things down the line
  if (inputDate.compareTo(context.toLocalDate(subscription.getStartDate())) == 0 && tmp.compareTo(subscription.getStartDate()) < 0) {
    return subscription.getStartDate();
  } else {
    return tmp;
  }
}

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

/**
 * See {@link android.text.format.DateUtils#isToday} for full docs.
 *
 * @return true if the supplied when is today else false
 */
public static boolean isToday(ReadablePartial time) {
  if (!time.isSupported(DateTimeFieldType.dayOfMonth())
    || !time.isSupported(DateTimeFieldType.monthOfYear())
    || !time.isSupported(DateTimeFieldType.year())) {
    throw new IllegalArgumentException("isToday() must be passed a ReadablePartial that supports day of " +
      "month, month of year and year.");
  }
  LocalDate localDate = time instanceof LocalDate ? (LocalDate) time : new LocalDate(time);
  return LocalDate.now().compareTo(localDate) == 0;
}

代码示例来源: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", enabled = false)
public void testWithGMTMinus20() throws SQLException {
  final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_MINUS_20_GMT));
  // We chose a time such that it moves to next day
  final DateTime date2_1 = new DateTime(2014, 10, 1, 16, 48, 56, DATE_TZ_MINUS_20_GMT);
  insertData(date1_1, date2_1, date2_1);
  final FullOfDates result = readData();
  assertEquals(result.getDate1().compareTo(date1_1), 0);
  assertEquals(result.getDate2().compareTo(date2_1), 0);
  assertEquals(result.getDate2().getZone().toString(), "UTC");
}

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

@Test(groups = "slow", enabled = false)
public void testWithGMTPlus8() throws SQLException {
  final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_PLUS_8_GMT));
  // We chose a time such that it moves to next day
  final DateTime date2_1 = new DateTime(2014, 10, 1, 22, 48, 56, DATE_TZ_PLUS_8_GMT);
  insertData(date1_1, date2_1, date2_1);
  final FullOfDates result = readData();
  assertEquals(result.getDate1().compareTo(date1_1), 0);
  assertEquals(result.getDate2().compareTo(date2_1), 0);
  assertEquals(result.getDate2().getZone().toString(), "UTC");
}

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

assertEquals(result.size(), 3);
assertEquals(result.get(0).getSubscriptionId(), subscriptionId);
assertEquals(result.get(0).getRecordDate().compareTo(startDate), 0);
assertEquals(result.get(0).getUnitType(), unitType1);
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);
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

public void checkAddonCreationRights(final SubscriptionBase baseSubscription, final Plan targetAddOnPlan, final DateTime requestedDate, final InternalTenantContext context)
    throws SubscriptionBaseApiException {
  if (baseSubscription.getState() == EntitlementState.CANCELLED ||
    (baseSubscription.getState() == EntitlementState.PENDING && context.toLocalDate(baseSubscription.getStartDate()).compareTo(context.toLocalDate(requestedDate)) < 0)) {
    throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_BP_NON_ACTIVE, targetAddOnPlan.getName());
  }
  final Plan currentOrPendingPlan = baseSubscription.getCurrentOrPendingPlan();
  final Product baseProduct = currentOrPendingPlan.getProduct();
  if (isAddonIncluded(baseProduct, targetAddOnPlan)) {
    throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_ALREADY_INCLUDED,
                        targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName());
  }
  if (!isAddonAvailable(baseProduct, targetAddOnPlan)) {
    throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_AO_NOT_AVAILABLE,
                        targetAddOnPlan.getName(), currentOrPendingPlan.getProduct().getName());
  }
}

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

if (!noEvents && (requestedDate == null || requestedDate.compareTo(clock.getUTCToday()) <= 0)) {
  testListener.pushExpectedEvent(NextEvent.CREATE);

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

@Override
  public int compare(final Invoice i1, final Invoice i2) {
    final LocalDate d1 = i1.getInvoiceDate();
    final LocalDate d2 = i2.getInvoiceDate();
    if (d1.compareTo(d2) == 0) {
      return i1.hashCode() - i2.hashCode(); // consistent (arbitrary) resolution for tied dates
    }
    return d1.compareTo(d2);
  }
}

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

public boolean isItemOverlap(final NodeInterval newNode) {
  return ((newNode.getStart().compareTo(start) < 0 &&
       newNode.getEnd().compareTo(end) >= 0) ||
      (newNode.getStart().compareTo(start) <= 0 &&
       newNode.getEnd().compareTo(end) > 0));
}

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

@Override
  public int compare(final Invoice i1, final Invoice i2) {
    final LocalDate d1 = i1.getInvoiceDate();
    final LocalDate d2 = i2.getInvoiceDate();
    if (d1.compareTo(d2) == 0) {
      return i1.hashCode() - i2.hashCode(); // consistent (arbitrary) resolution for tied dates
    }
    return d1.compareTo(d2);
  }
}

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

/**
 * Check if the date portion of a date/time is equals at today (as returned by the clock).
 *
 * @param inputDate       the fully qualified DateTime
 * @param accountTimeZone the account timezone
 * @return true if the inputDate, once converted into a LocalDate using account timezone is equals at today
 */
private boolean isEqualsToday(final DateTime inputDate, final DateTimeZone accountTimeZone) {
  final LocalDate localDateNowInAccountTimezone = new LocalDate(clock.getUTCNow(), accountTimeZone);
  final LocalDate targetDateInAccountTimezone = new LocalDate(inputDate, accountTimeZone);
  return targetDateInAccountTimezone.compareTo(localDateNowInAccountTimezone) == 0;
}

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

@Override
  public int compare(final InvoiceModelDao i1, final InvoiceModelDao i2) {
    return i1.getInvoiceDate().compareTo(i2.getInvoiceDate());
  }
}).immutableSortedCopy(unpaidInvoices);

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

@Override
  public boolean apply(final InvoiceModelDao invoice) {
    return !invoice.isMigrated() && invoice.getTargetDate().compareTo(fromDate) >= 0;
  }
})));

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

@Override
  public boolean apply(final InvoiceItem input) {
    if (input.getInvoiceItemType() != InvoiceItemType.USAGE) {
      return false;
    }
    // STEPH what happens if we discover usage period that overlap (one side or both side) the [startDate, endDate] interval
    final UsageInvoiceItem usageInput = (UsageInvoiceItem) input;
    return usageInput.getUsageName().equals(usage.getName()) &&
        usageInput.getStartDate().compareTo(startDate) >= 0 &&
        usageInput.getEndDate().compareTo(endDate) <= 0;
  }
});

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

@Test(groups = "fast")
public void testNullConversion() {
  ((ClockMock) clock).setTime(new DateTime("2013-08-26T06:50:20Z"));
  final String input = null;
  final LocalDate result = toLocalDate(accountId, input, null);
  Assert.assertTrue(result.compareTo(new LocalDate(2013, 8, 25)) == 0);
  ((ClockMock) clock).resetDeltaFromReality();
}

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

private boolean shouldSwap(final SubscriptionEvent cur, final SubscriptionEvent other, final boolean isAscending) {
  // For a given date, order by subscriptionId, and within subscription by event type
  final int idComp = cur.getEntitlementId().compareTo(other.getEntitlementId());
  return (cur.getEffectiveDate().compareTo(other.getEffectiveDate()) == 0 &&
      ((isAscending &&
       ((idComp > 0) ||
        (idComp == 0 && compareSubscriptionEventsForSameEffectiveDateAndEntitlementId(cur, other) > 0))) ||
       (!isAscending &&
       ((idComp < 0) ||
        (idComp == 0 && compareSubscriptionEventsForSameEffectiveDateAndEntitlementId(cur, other) < 0)))));
}

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

@Test(groups = "slow", enabled = false)
public void testWithGMTMinus20() throws SQLException {
  final LocalDate date1_1 = new LocalDate(2014, 10, 1, GregorianChronology.getInstance(DATE_TZ_MINUS_20_GMT));
  // We chose a time such that it moves to next day
  final DateTime date2_1 = new DateTime(2014, 10, 1, 16, 48, 56, DATE_TZ_MINUS_20_GMT);
  insertData(date1_1, date2_1, date2_1);
  final FullOfDates result = readData();
  assertEquals(result.getDate1().compareTo(date1_1), 0);
  assertEquals(result.getDate2().compareTo(date2_1), 0);
  assertEquals(result.getDate2().getZone().toString(), "UTC");
}

相关文章