Represents a date using an integer, in a similar fashion to the
implementation in Microsoft Excel. The range of dates supported is
1-Jan-1900 to 31-Dec-9999.
Be aware that there is a deliberate bug in Excel that recognises the year
1900 as a leap year when in fact it is not a leap year. You can find more
information on the Microsoft website in article Q181370:
Excel uses the convention that 1-Jan-1900 = 1. This class uses the
convention 1-Jan-1900 = 2.
The result is that the day number in this class will be different to the
Excel figure for January and February 1900...but then Excel adds in an extra
day (29-Feb-1900 which does not actually exist!) and from that point forward
the day numbers will match.
| Method from org.jfree.date.SpreadsheetDate Detail: |
public int compare(SerialDate other) {
return this.serial - other.toSerial();
}
Returns the difference (in days) between this date and the specified
'other' date. |
public int compareTo(Object other) {
return compare((SerialDate) other);
}
Implements the method required by the Comparable interface. |
public boolean equals(Object object) {
if (object instanceof SerialDate) {
final SerialDate s = (SerialDate) object;
return (s.toSerial() == this.toSerial());
}
else {
return false;
}
}
Tests the equality of this date with an arbitrary object.
This method will return true ONLY if the object is an instance of the
SerialDate base class, and it represents the same day as this
SpreadsheetDate . |
public int getDayOfMonth() {
return this.day;
}
Returns the day of the month. |
public int getDayOfWeek() {
return (this.serial + 6) % 7 + 1;
}
Returns a code representing the day of the week.
The codes are defined in the SerialDate class as:
SUNDAY, MONDAY, TUESDAY,
WEDNESDAY, THURSDAY, FRIDAY, and
SATURDAY. |
public int getMonth() {
return this.month;
}
Returns the month (January = 1, February = 2, March = 3). |
public int getYYYY() {
return this.year;
}
Returns the year (assume a valid range of 1900 to 9999). |
public int hashCode() {
return toSerial();
}
Returns a hash code for this object instance. |
public boolean isAfter(SerialDate other) {
return (this.serial > other.toSerial());
}
Returns true if this SerialDate represents the same date as the
specified SerialDate. |
public boolean isBefore(SerialDate other) {
return (this.serial < other.toSerial());
}
Returns true if this SerialDate represents an earlier date compared to
the specified SerialDate. |
public boolean isInRange(SerialDate d1,
SerialDate d2) {
return isInRange(d1, d2, SerialDate.INCLUDE_BOTH);
}
Returns true if this SerialDate is within the
specified range (INCLUSIVE). The date order of d1 and d2 is not
important. |
public boolean isInRange(SerialDate d1,
SerialDate d2,
int include) {
final int s1 = d1.toSerial();
final int s2 = d2.toSerial();
final int start = Math.min(s1, s2);
final int end = Math.max(s1, s2);
final int s = toSerial();
if (include == SerialDate.INCLUDE_BOTH) {
return (s >= start && s < = end);
}
else if (include == SerialDate.INCLUDE_FIRST) {
return (s >= start && s < end);
}
else if (include == SerialDate.INCLUDE_SECOND) {
return (s > start && s < = end);
}
else {
return (s > start && s < end);
}
}
Returns true if this SerialDate is within the specified range (caller
specifies whether or not the end-points are included). The order of d1
and d2 is not important. |
public boolean isOn(SerialDate other) {
return (this.serial == other.toSerial());
}
Returns true if this SerialDate represents the same date as the
specified SerialDate. |
public boolean isOnOrAfter(SerialDate other) {
return (this.serial >= other.toSerial());
}
Returns true if this SerialDate represents the same date as the
specified SerialDate. |
public boolean isOnOrBefore(SerialDate other) {
return (this.serial < = other.toSerial());
}
Returns true if this SerialDate represents the same date as the
specified SerialDate. |
public Date toDate() {
final Calendar calendar = Calendar.getInstance();
calendar.set(getYYYY(), getMonth() - 1, getDayOfMonth(), 0, 0, 0);
return calendar.getTime();
}
Returns a java.util.Date equivalent to this date. |
public int toSerial() {
return this.serial;
}
Returns the serial number for the date, where 1 January 1900 = 2
(this corresponds, almost, to the numbering system used in Microsoft
Excel for Windows and Lotus 1-2-3). |