List of usage examples for org.joda.time.base AbstractInstant compareTo
public int compareTo(ReadableInstant other)
From source file:nl.knaw.dans.common.lang.repo.AbstractTimestampedObject.java
License:Apache License
/** * Compare date with compareDate./* w w w. j ava 2 s . c o m*/ * * @param date * one of the objects recognized in <a * href="http://joda-time.sourceforge.net/api-release/org/joda/time/convert/ConverterManager.html" * >ConverterManager</a> * @param compareDate * one of the objects recognized in <a * href="http://joda-time.sourceforge.net/api-release/org/joda/time/convert/ConverterManager.html" * >ConverterManager</a> * @return negative value if date is less, 0 if equal, or positive value if greater. 0 if one of the parameters is * null. * @throws IllegalArgumentException * if date or compareDate could not be converted. */ public static int compare(final Object date, final Object compareDate) throws IllegalArgumentException { AbstractInstant dateTime; AbstractInstant compareDateTime; if (date == null) { LOGGER.warn("Could not determine ancienity: date is null."); return 0; } else if (compareDate == null) { LOGGER.warn("Could not determine ancienity: compareDate is null."); return 0; } if (date instanceof AbstractInstant) { dateTime = (AbstractInstant) date; } else { dateTime = new DateTime(date); } if (compareDate instanceof AbstractInstant) { compareDateTime = (AbstractInstant) compareDate; } else { compareDateTime = new DateTime(compareDate); } return dateTime.compareTo(compareDateTime); }