@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); } }
/** * 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; }
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; } }
/** * 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; }
@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); }
@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"); }
@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"); }
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);
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()); } }
if (!noEvents && (requestedDate == null || requestedDate.compareTo(clock.getUTCToday()) <= 0)) { testListener.pushExpectedEvent(NextEvent.CREATE);
@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); } }
@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); } }
/** * 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; }
@Override public int compare(final InvoiceModelDao i1, final InvoiceModelDao i2) { return i1.getInvoiceDate().compareTo(i2.getInvoiceDate()); } }).immutableSortedCopy(unpaidInvoices);
@Override public boolean apply(final InvoiceModelDao invoice) { return !invoice.isMigrated() && invoice.getTargetDate().compareTo(fromDate) >= 0; } })));
@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; } });
@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(); }
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))))); }
@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"); }