|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.afcs.warts.util.DateComparator
The DateComparator class provides various utilities related to the comparison of dates.
The first utility is a comparator (in the DATE_COMPARATOR
field,
that can be used to compare dates, and hence sort them in a list.
The second utility is a method that can turn the difference between two dates into human-readable text (e.g., "less than 2 minutes ago").
Another method is a utility that allows users to quickly determine if the difference between two dates is less than some range.
LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.
Field Summary | |
static java.util.Comparator |
DATE_COMPARATOR
This comparator can be used to compare dates. |
static long |
DAY
The number of milliseconds in a day. |
static long |
HOUR
The number of milliseconds in an hour. |
static long |
MINUTE
The number of milliseconds in a minute. |
static long |
SECOND
The number of milliseconds in a second. |
Method Summary | |
static boolean |
absoluteTimeDifferenceLessThan(java.util.Date baseDate,
java.util.Date compareToDate,
long unitInMilliseconds,
int numUnits)
Returns true if the difference between the specified "compare to" date and the source date that the instance was initialied with is less than the specified number of units of the specified units of time (which are specified in milliseconds). |
static java.lang.String |
getDateDifferenceText(java.util.Date baseDate,
java.util.Date compareToDate)
Returns text describing the difference between the two dates. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.util.Comparator DATE_COMPARATOR
public static final long SECOND
public static final long MINUTE
public static final long HOUR
public static final long DAY
Method Detail |
public static boolean absoluteTimeDifferenceLessThan(java.util.Date baseDate, java.util.Date compareToDate, long unitInMilliseconds, int numUnits)
boolean lessThanAnHourAgo = DateComparator.absoluteTimeDifferenceLessThan( someDate, someOtherDate, DateComparator.HOUR, 1);
Note that only the absolute difference between the two dates is considered.
baseDate
- The base date in the comparison.compareToDate
- The date to compare the base date against.unitInMilliseconds
- A unit of time, specified in milliseconds.
Users are encouraged to use the constants defined
in this class to make code more readable.numUnits
- The number of units of time to consider.
java.lang.NullPointerException
- If baseDate or compareDate is null.public static java.lang.String getDateDifferenceText(java.util.Date baseDate, java.util.Date compareToDate)
baseDate
- The base date in the comparison.compareToDate
- The date to compare the base date against.
java.lang.NullPointerException
- If baseDate or compareDate is null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |