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:com.excilys.sugadroid.util.EagerLoadingCalendar.java

License:Open Source License

public void setMinPastLoadingDay(LocalDate minPastLoadingDay) {

    if (minPastLoadingDay.compareTo(this.minPastLoadingDay) < 0) {
        this.minPastLoadingDay = minPastLoadingDay;
    } else {//w  w  w. j  a va2 s  . c  om
        Log.i(TAG, "old minPastLoadingDay before new one, old: " + this.minPastLoadingDay + ", new: "
                + minPastLoadingDay);
    }
}

From source file:com.excilys.sugadroid.util.EagerLoadingCalendar.java

License:Open Source License

public void setMaxFutureLoadingDay(LocalDate maxFutureLoadingDay) {
    if (maxFutureLoadingDay.compareTo(this.maxFutureLoadingDay) > 0) {
        this.maxFutureLoadingDay = maxFutureLoadingDay;
    } else {/*w ww . ja v a 2  s . c o  m*/
        Log.i(TAG, "old maxFutureLoadingDay after new one, old: " + this.maxFutureLoadingDay + ", new: "
                + maxFutureLoadingDay);
    }
}

From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java

License:Apache License

public static LocalDate calculateBillingCycleDateAfter(final LocalDate date, final int billingCycleDayLocal) {
    LocalDate proposedDate = calculateBillingCycleDateOnOrAfter(date, billingCycleDayLocal);
    if (date.compareTo(proposedDate) == 0) {
        proposedDate = proposedDate.plusMonths(1);
    }/*  ww w  .  j a  va 2s.c o m*/
    return proposedDate;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

/**
 * <code>null</code> safe compare.<br>
 * Note: it has the same semantics as/*from  w ww . ja  va 2s  .c om*/
 * {@link com.phloc.commons.compare.CompareUtils#nullSafeCompare(Comparable, Comparable)}
 * except that the parameter class does not implement
 * {@link java.lang.Comparable} in a Generics-way!
 *
 * @param aDate1
 *        First object. May be <code>null</code>.
 * @param aDate2
 *        Second object. May be <code>null</code>.
 * @return -1, 0 or +1
 */
public static int nullSafeCompare(@Nullable final LocalDate aDate1, @Nullable final LocalDate aDate2) {
    return aDate1 == aDate2 ? 0 : aDate1 == null ? -1 : aDate2 == null ? +1 : aDate1.compareTo(aDate2);
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreater(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2) {
    return aDate1.compareTo(aDate2) > 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isGreaterOrEqual(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2) {
    return aDate1.compareTo(aDate2) >= 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLess(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2) {
    return aDate1.compareTo(aDate2) < 0;
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

public static boolean isLessOrEqual(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2) {
    return aDate1.compareTo(aDate2) <= 0;
}

From source file:com.sonicle.webtop.calendar.CalendarManager.java

License:Open Source License

private <T> List<T> calculateRecurringInstances_OLD(Connection con, RecurringInstanceMapper<T> instanceMapper,
        DateTime fromDate, DateTime toDate, DateTimeZone userTimezone, int limit) throws WTException {
    RecurrenceDAO recDao = RecurrenceDAO.getInstance();
    RecurrenceBrokenDAO recbDao = RecurrenceBrokenDAO.getInstance();
    ArrayList<T> instances = new ArrayList<>();

    int eventId = instanceMapper.getEventId();
    DateTime eventStartDate = instanceMapper.getEventStartDate();
    DateTime eventEndDate = instanceMapper.getEventEndDate();

    // Retrieves reccurence and broken dates (if any)
    ORecurrence orec = recDao.selectByEvent(con, eventId);
    if (orec == null) {
        logger.warn("Unable to retrieve recurrence for event [{}]", eventId);

    } else {/*w w  w.j  av  a2 s .c  o m*/
        if (fromDate == null)
            fromDate = orec.getStartDate();
        if (toDate == null)
            toDate = orec.getStartDate().plusYears(1);

        /*
        List<ORecurrenceBroken> obrecs = recbDao.selectByEventRecurrence(con, eventId, orec.getRecurrenceId());
        //TODO: ritornare direttamente l'hashmap da jooq
        // Builds a hashset of broken dates for increasing performances
        HashMap<String, ORecurrenceBroken> brokenDates = new HashMap<>();
        for (ORecurrenceBroken obrec : obrecs) {
           brokenDates.put(obrec.getEventDate().toString(), obrec);
        }
        */

        Map<LocalDate, ORecurrenceBroken> obrecs = recbDao.selectByEventRecurrence(con, eventId,
                orec.getRecurrenceId());
        HashSet<String> brokenDates = new HashSet<>();
        for (LocalDate ld : obrecs.keySet()) {
            brokenDates.add(ld.toString());
        }

        try {
            // Calculate event length in order to generate events like original one
            int eventDays = CalendarUtils.calculateLengthInDays(eventStartDate, eventEndDate);
            RRule rr = new RRule(orec.getRule());

            // Calcutate recurrence set for required dates range
            PeriodList periods = ICal4jUtils.calculateRecurrenceSet(eventStartDate, eventEndDate,
                    orec.getStartDate(), rr, fromDate, toDate, userTimezone);

            // Recurrence start is useful to skip undesired dates at beginning.
            // If event does not starts at recurrence real beginning (eg. event
            // start on MO but first recurrence begin on WE), ical4j lib includes 
            // those dates in calculated recurrence set, as stated in RFC 
            // (http://tools.ietf.org/search/rfc5545#section-3.8.5.3).
            LocalDate rrStart = ICal4jUtils
                    .calculateRecurrenceStart(orec.getStartDate(), rr.getRecur(), userTimezone).toLocalDate();
            //LocalDate rrStart = ICal4jUtils.calculateRecurrenceStart(eventStartDate, rr.getRecur(), userTimezone).toLocalDate(); //TODO: valutare se salvare la data gi aggiornata
            LocalDate rrEnd = orec.getUntilDate().toLocalDate();

            // Iterates returned recurring periods and builds cloned events...
            int count = -1;
            for (net.fortuna.ical4j.model.Period per : (Iterable<net.fortuna.ical4j.model.Period>) periods) {
                count++;
                if ((limit != -1) && (count > limit))
                    break;
                final LocalDate perStart = ICal4jUtils.toJodaDateTime(per.getStart()).toLocalDate();
                final LocalDate perEnd = ICal4jUtils.toJodaDateTime(per.getEnd()).toLocalDate();

                if (brokenDates.contains(perStart.toString()))
                    continue; // Skip broken dates...
                if ((perStart.compareTo(rrStart) >= 0) && (perEnd.compareTo(rrEnd) <= 0)) { // Skip unwanted dates at beginning
                    final DateTime newStart = eventStartDate.withDate(perStart);
                    final DateTime newEnd = eventEndDate.withDate(newStart.plusDays(eventDays).toLocalDate());
                    final String key = EventKey.buildKey(eventId, eventId, perStart);

                    instances.add(instanceMapper.createInstance(key, newStart, newEnd));
                }
            }

        } catch (DAOException ex) {
            throw wrapException(ex);
        } catch (ParseException ex) {
            throw new WTException(ex, "Unable to parse rrule");
        }
    }
    return instances;
}

From source file:com.sonicle.webtop.core.Service.java

License:Open Source License

public void processManageGridIMChatMessages(HttpServletRequest request, HttpServletResponse response,
        PrintWriter out) {//from w  w w  . j ava2 s  .  c  o  m
    UserProfile up = getEnv().getProfile();
    DateTimeZone utz = up.getTimeZone();

    try {
        String crud = ServletUtils.getStringParameter(request, "crud", true);
        if (crud.equals(Crud.READ)) {
            String chatId = ServletUtils.getStringParameter(request, "chatId", true);
            String date = ServletUtils.getStringParameter(request, "date", null);

            final LocalDate nowLd = DateTime.now().withZone(utz).toLocalDate();
            LocalDate ld = (date == null) ? nowLd
                    : DateTimeUtils.parseYmdHmsWithZone(date, "00:00:00", utz).toLocalDate();
            boolean history = (ld.compareTo(nowLd) != 0);

            IMChat chat = coreMgr.getIMChat(chatId);
            if (xmppCli != null) {
                List<JsGridIMMessage> items = new ArrayList<>();
                EntityBareJid chatJid = XMPPHelper.asEntityBareJid(chatId);
                EntityBareJid myJid = xmppCli.getUserJid().asEntityBareJid();

                final DateTime messageTs = ChatMessage.nowTimestamp();
                LocalDate lastDate = null;

                HashMap<String, String> cacheNicks = new HashMap<>();
                cacheNicks.put(myJid.toString(), xmppCli.getUserNickame()); // Fill cache with my data
                List<IMMessage> messages = coreMgr.listIMMessages(chatId, ld, utz, !history);

                // Add unavailable warning at the beginning
                if (history && !messages.isEmpty()) {
                    if (chat != null && chat.isUnavailable()) {
                        final String msgId = ChatMessage.buildUniqueId(chatJid, "dummy-unavailable1",
                                messageTs);
                        items.add(JsGridIMMessage.asWarnAction(msgId, messageTs, "unavailable"));
                    }
                }

                for (IMMessage mes : messages) {
                    final LocalDate mesDate = mes.getTimestampDate(utz);
                    if (!mesDate.equals(lastDate)) {
                        lastDate = mesDate;
                        final String msgId = ChatMessage.buildUniqueId(chatJid, "dummy-date",
                                mes.getTimestamp());
                        items.add(JsGridIMMessage.asDateAction(msgId, lastDate));
                    }

                    if (!cacheNicks.containsKey(mes.getSenderJid())) {
                        if (xmppCli.isAuthenticated()) {
                            cacheNicks.put(mes.getSenderJid(),
                                    xmppCli.getFriendNickname(XMPPHelper.asEntityBareJid(mes.getSenderJid())));
                        } else {
                            cacheNicks.put(mes.getSenderJid(),
                                    XMPPHelper.buildGuessedString(mes.getSenderJid()));
                        }
                    }
                    final String nick = cacheNicks.get(mes.getSenderJid());
                    items.add(new JsGridIMMessage(myJid.equals(mes.getSenderJid()), mes, nick, utz));
                }

                // Add unavailable warning at the end
                if (chat != null && chat.isUnavailable()) {
                    final String msgId = ChatMessage.buildUniqueId(chatJid, "dummy-unavailable2", messageTs);
                    items.add(JsGridIMMessage.asWarnAction(msgId, messageTs, "unavailable"));
                }

                new JsonResult(items, items.size()).printTo(out);

            } else {
                throw new WTException("XMPPClient not available");
            }
        }

    } catch (Exception ex) {
        logger.error("Error in ManageGridIMChatMessages", ex);
        new JsonResult(ex).printTo(out);
    }
}