summaryrefslogtreecommitdiff
path: root/java/util/Calendar.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2006-12-10 20:25:39 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2006-12-10 20:25:39 +0000
commitda66af5951b18b6f5e8752cbbe11f5f842332a33 (patch)
treea28e126d1415e3689be6c7b2c2d061ae51194195 /java/util/Calendar.java
parentab90923ee693a17e2e0e37b6ba5a84794c9236de (diff)
downloadclasspath-da66af5951b18b6f5e8752cbbe11f5f842332a33.tar.gz
2006-12-10 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of generics-branch to HEAD (woohoo!)
Diffstat (limited to 'java/util/Calendar.java')
-rw-r--r--java/util/Calendar.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/java/util/Calendar.java b/java/util/Calendar.java
index f48de85f1..8c46c0193 100644
--- a/java/util/Calendar.java
+++ b/java/util/Calendar.java
@@ -104,7 +104,8 @@ day_of_week + week_of_year</pre>
* @see TimeZone
* @see java.text.DateFormat
*/
-public abstract class Calendar implements Serializable, Cloneable
+public abstract class Calendar
+ implements Serializable, Cloneable, Comparable<Calendar>
{
/**
* Constant representing the era time field.
@@ -1219,6 +1220,31 @@ public abstract class Calendar implements Serializable, Cloneable
}
/**
+ * Compares the time of two calendar instances.
+ * @param calendar the calendar to which the time should be compared.
+ * @return 0 if the two calendars are set to the same time,
+ * less than 0 if the time of this calendar is before that of
+ * <code>cal</code>, or more than 0 if the time of this calendar is after
+ * that of <code>cal</code>.
+ *
+ * @param cal the calendar to compare this instance with.
+ * @throws NullPointerException if <code>cal</code> is null.
+ * @throws IllegalArgumentException if either calendar has fields set to
+ * invalid values.
+ * @since 1.5
+ */
+ public int compareTo(Calendar cal)
+ {
+ long t1 = getTimeInMillis();
+ long t2 = cal.getTimeInMillis();
+ if(t1 == t2)
+ return 0;
+ if(t1 > t2)
+ return 1;
+ return -1;
+ }
+
+ /**
* Return a clone of this object.
*/
public Object clone()