/** * Compare two objects against only the range of date time fields as * specified in the constructor. * * @param lhsObj the first object, * logically on the left of a < comparison, null means now * @param rhsObj the second object, * logically on the right of a < comparison, null means now * @return zero if order does not matter, * negative value if lhsObj < rhsObj, positive value otherwise. * @throws IllegalArgumentException if either argument is not supported */ public int compare(Object lhsObj, Object rhsObj) { InstantConverter conv = ConverterManager.getInstance().getInstantConverter(lhsObj); Chronology lhsChrono = conv.getChronology(lhsObj, (Chronology) null); long lhsMillis = conv.getInstantMillis(lhsObj, lhsChrono); conv = ConverterManager.getInstance().getInstantConverter(rhsObj); Chronology rhsChrono = conv.getChronology(rhsObj, (Chronology) null); long rhsMillis = conv.getInstantMillis(rhsObj, rhsChrono); if (iLowerLimit != null) { lhsMillis = iLowerLimit.getField(lhsChrono).roundFloor(lhsMillis); rhsMillis = iLowerLimit.getField(rhsChrono).roundFloor(rhsMillis); } if (iUpperLimit != null) { lhsMillis = iUpperLimit.getField(lhsChrono).remainder(lhsMillis); rhsMillis = iUpperLimit.getField(rhsChrono).remainder(rhsMillis); } if (lhsMillis < rhsMillis) { return -1; } else if (lhsMillis > rhsMillis) { return 1; } else { return 0; } }
/** * Constructs an instance from an Object that represents a datetime, * forcing the time zone to that specified. * <p> * If the object contains no chronology, <code>ISOChronology</code> is used. * If the specified time zone is null, the default zone is used. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadableInstant, String, Calendar and Date. * * @param instant the datetime object * @param zone the time zone * @throws IllegalArgumentException if the instant is invalid */ public BaseDateTime(Object instant, DateTimeZone zone) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); Chronology chrono = checkChronology(converter.getChronology(instant, zone)); iChronology = chrono; iMillis = checkInstant(converter.getInstantMillis(instant, chrono), chrono); }
/** * Constructs an instance from an Object that represents a datetime, * using the specified chronology. * <p> * If the chronology is null, ISO in the default time zone is used. * <p> * The recognised object types are defined in * {@link org.joda.time.convert.ConverterManager ConverterManager} and * include ReadableInstant, String, Calendar and Date. * * @param instant the datetime object * @param chronology the chronology * @throws IllegalArgumentException if the instant is invalid */ public BaseDateTime(Object instant, Chronology chronology) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); iChronology = checkChronology(converter.getChronology(instant, chronology)); iMillis = checkInstant(converter.getInstantMillis(instant, chronology), iChronology); }
/** * Constructs an instance from an Object that represents a datetime. * <p> * The recognised object types are defined in {@link ConverterManager} and * include String, Calendar and Date. * * @param instant the datetime object, null means now * @throws IllegalArgumentException if the instant is invalid */ public Instant(Object instant) { super(); InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant); iMillis = converter.getInstantMillis(instant, ISOChronology.getInstanceUTC()); }