Example usage for org.joda.time LocalDate compareTo

List of usage examples for org.joda.time LocalDate compareTo

Introduction

In this page you can find the example usage for org.joda.time LocalDate compareTo.

Prototype

public int compareTo(ReadablePartial partial) 

Source Link

Document

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

Usage

From source file:org.estatio.dom.lease.LeaseTermForTesting.java

License:Apache License

@Override
public BigDecimal valueForDate(LocalDate date) {
    // after the end date the adjusted value is returned
    if (getEndDate() != null && date.compareTo(getEndDate()) >= 0) {
        return adjustedValue != null ? adjustedValue : value;
    }/*from   ww  w  .  j  av a 2  s  .co  m*/
    return value;
}

From source file:org.estatio.dom.utils.CalendarUtils.java

License:Apache License

public static Interval currentInterval(final LocalDate date, final String rrule, final LocalDate startDate) {
    if (date == null || startDate == null || rrule == null) {
        return null;
    }//from w w  w.  j  a  v a 2  s . c  o m
    try {
        LocalDate thisDate = startDate;
        final LocalDateIterator iter = LocalDateIteratorFactory.createLocalDateIterator(rrule, thisDate, true);
        while (iter.hasNext()) {
            LocalDate nextDate = iter.next();
            if (nextDate.compareTo(date) > 0) {
                return new Interval(thisDate.toInterval().getStartMillis(),
                        nextDate.toInterval().getStartMillis());
            }
            thisDate = nextDate;
        }
    } catch (final ParseException ex) {
        throw new EstatioApplicationException("Unable to parse rrule >>" + rrule + "<<", ex);
    }
    return null;
}

From source file:org.estatio.dom.utils.CalendarUtils.java

License:Apache License

public static boolean isBetween(final LocalDate date, final LocalDate startDate, final LocalDate endDate) {
    if (startDate != null && date.compareTo(startDate) >= 0
            && (endDate == null || date.compareTo(endDate) <= 0)) {
        return true;
    }/*from ww w.java  2 s  .  c  om*/
    return false;
}

From source file:org.estatio.dom.utils.CalendarUtils.java

License:Apache License

public static List<Interval> intervalsInRange(final LocalDate startDate, final LocalDate endDate,
        final String rrule) {
    if (startDate.compareTo(endDate) > 0) {
        throw new IllegalArgumentException(
                String.format("Start date %s is after end date %s", startDate.toString(), endDate.toString()));
    }/*ww  w . j  a v a  2  s  .com*/
    List<Interval> intervals = Lists.newArrayList();
    LocalDate start = startDate;
    Interval interval = null;
    do {
        interval = intervalContaining(start, rrule);
        if (interval != null) {
            intervals.add(interval);
            start = interval.getEnd().toLocalDate();
        }
    } while (interval != null && start.isBefore(endDate));
    return intervals;
}

From source file:org.estatio.dscm.dom.playlist.Playlist.java

License:Apache License

@Programmatic
public List<LocalDateTime> nextOccurences(LocalDate endDate) {
    List<LocalDateTime> nextList = new ArrayList<LocalDateTime>();
    final LocalDate start = getStartDate().isBefore(clockService.now()) ? clockService.now() : getStartDate();
    final LocalDate end = ObjectUtils.min(endDate, getEndDate());

    if (end.compareTo(start) >= 0 && end.compareTo(clockService.now()) >= 0) {
        List<Interval> intervals = CalendarUtils.intervalsInRange(start, end, getRepeatRule());

        for (Interval interval : intervals) {
            nextList.add(//from   ww  w  .  j av  a2s. co m
                    new LocalDateTime(interval.getStartMillis()).withHourOfDay(getStartTime().getHourOfDay())
                            .withMinuteOfHour(getStartTime().getMinuteOfHour()));
        }
    }

    return nextList;
}

From source file:org.estatio.dscm.utils.CalendarUtils.java

License:Apache License

public static Interval currentInterval(final LocalDate date, final String rrule, final LocalDate startDate) {
    if (date == null || startDate == null || rrule == null) {
        return null;
    }/*  w w w  . jav a2  s.  co  m*/
    try {
        LocalDate thisDate = startDate;
        final LocalDateIterator iter = LocalDateIteratorFactory.createLocalDateIterator(rrule, thisDate, true);
        while (iter.hasNext()) {
            LocalDate nextDate = iter.next();
            if (nextDate.compareTo(date) > 0) {
                return new Interval(thisDate.toInterval().getStartMillis(),
                        nextDate.toInterval().getStartMillis());
            }
            thisDate = nextDate;
        }
    } catch (final ParseException ex) {
        throw new IllegalArgumentException("Unable to parse rrule >>" + rrule + "<<", ex);
    }
    return null;
}

From source file:org.estatio.fixturescripts.FixLeaseTerms.java

License:Apache License

private boolean fixEffectiveDate(LeaseTermForIndexable term) {
    LocalDate indexAvailableDate = term.getNextIndexStartDate() == null ? null
            : term.getNextIndexStartDate().plusMonths(2).plusDays(16);
    LocalDate effectiveDate = null;
    if (indexAvailableDate != null && indexAvailableDate.compareTo(term.getStartDate()) > 0
            && term.getSettledValue() == null) {
        effectiveDate = term.getLeaseItem().getInvoicingFrequency().intervalContaining(indexAvailableDate)
                .endDateExcluding();/*from  w  w w  .  ja  v a 2  s.com*/
    }
    if (!ObjectUtils.equals(effectiveDate, term.getEffectiveDate())) {
        term.setEffectiveDate(effectiveDate);
        return true;
    }
    return false;
}

From source file:org.gnucash.android.ui.transaction.TransactionsActivity.java

License:Apache License

/**
 * Formats the date to show the the day of the week if the {@code dateMillis} is within 7 days
 * of today. Else it shows the actual date formatted as short string. <br>
 * It also shows "today", "yesterday" or "tomorrow" if the date is on any of those days
 * @param dateMillis//from  w  w w .  ja va2s .  c  om
 * @return
 */
@NonNull
public static String getPrettyDateFormat(Context context, long dateMillis) {
    LocalDate transactionTime = new LocalDate(dateMillis);
    LocalDate today = new LocalDate();
    String prettyDateText = null;
    if (transactionTime.compareTo(today.minusDays(1)) >= 0
            && transactionTime.compareTo(today.plusDays(1)) <= 0) {
        prettyDateText = DateUtils
                .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS)
                .toString();
    } else if (transactionTime.getYear() == today.getYear()) {
        prettyDateText = mDayMonthDateFormat.format(new Date(dateMillis));
    } else {
        prettyDateText = DateUtils.formatDateTime(context, dateMillis,
                DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR);
    }

    return prettyDateText;
}

From source file:org.killbill.billing.beatrix.util.InvoiceChecker.java

License:Apache License

public void checkChargedThroughDate(final UUID entitlementId, final LocalDate expectedLocalCTD,
        final CallContext context) {
    try {//from   www  .j  ava2  s  .  co  m
        final DefaultEntitlement entitlement = (DefaultEntitlement) entitlementApi
                .getEntitlementForId(entitlementId, context);
        final SubscriptionBase subscription = entitlement.getSubscriptionBase();
        if (expectedLocalCTD == null) {
            assertNull(subscription.getChargedThroughDate());
        } else {
            assertTrue(expectedLocalCTD.compareTo(subscription.getChargedThroughDate().toLocalDate()) == 0);
            /*
            final DateTime expectedCTD = expectedLocalCTD.toDateTime(new LocalTime(subscription.getStartDate().getMillis(), DateTimeZone.UTC), DateTimeZone.UTC);
            final String msg = String.format("Checking CTD for entitlement %s : expectedLocalCTD = %s => expectedCTD = %s, got %s",
                                         entitlementId, expectedLocalCTD, expectedCTD, subscription.getChargedThroughDate());
            log.info(msg);
            assertNotNull(subscription.getChargedThroughDate());
            assertTrue(subscription.getChargedThroughDate().compareTo(expectedCTD) == 0, msg);
            */
        }
    } catch (EntitlementApiException e) {
        fail("Failed to retrieve entitlement for " + entitlementId);
    }
}

From source file:org.killbill.billing.entitlement.api.EntitlementDateHelper.java

License:Apache License

/**
 * Check if the date portion of a date/time is before or equals at now (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 less or equals than today
 *///from  w ww . jav  a  2 s . co m
// TODO Move to ClockUtils
public boolean isBeforeOrEqualsToday(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;
}