org.jfree.date

## Class SpreadsheetDate

- java.lang.Object
- - org.jfree.date.SerialDate
  - - org.jfree.date.SpreadsheetDate

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable, MonthConstants

      public class SpreadsheetDate
      extends SerialDate

  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:

  http://support.microsoft.com/support/kb/articles/Q181/3/70.asp

  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.

  Author:
    David Gilbert
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.jfree.date.SerialDate

      `AGGREGATE_DAYS_TO_END_OF_MONTH, AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH, DATE_FORMAT_SYMBOLS, FIRST_WEEK_IN_MONTH, FOLLOWING, FOURTH_WEEK_IN_MONTH, FRIDAY, INCLUDE_BOTH, INCLUDE_FIRST, INCLUDE_NONE, INCLUDE_SECOND, LAST_DAY_OF_MONTH, LAST_WEEK_IN_MONTH, LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_MONTH, LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH, MAXIMUM_YEAR_SUPPORTED, MINIMUM_YEAR_SUPPORTED, MONDAY, NEAREST, PRECEDING, SATURDAY, SECOND_WEEK_IN_MONTH, SERIAL_LOWER_BOUND, SERIAL_UPPER_BOUND, SUNDAY, THIRD_WEEK_IN_MONTH, THURSDAY, TUESDAY, WEDNESDAY`

    - ### Fields inherited from interface org.jfree.date.MonthConstants

      `APRIL, AUGUST, DECEMBER, FEBRUARY, JANUARY, JULY, JUNE, MARCH, MAY, NOVEMBER, OCTOBER, SEPTEMBER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SpreadsheetDate(int serial)` Standard constructor - creates a new date object representing the specified day number (which should be in the range 2 to 2958465.
    `SpreadsheetDate(int day, int month, int year)` Creates a new date instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(SerialDate other)` Returns the difference (in days) between this date and the specified 'other' date.
    `int` | `compareTo(java.lang.Object other)` Implements the method required by the Comparable interface.
    `boolean` | `equals(java.lang.Object object)` Tests the equality of this date with an arbitrary object.
    `int` | `getDayOfMonth()` Returns the day of the month.
    `int` | `getDayOfWeek()` Returns a code representing the day of the week.
    `int` | `getMonth()` Returns the month (January = 1, February = 2, March = 3).
    `int` | `getYYYY()` Returns the year (assume a valid range of 1900 to 9999).
    `int` | `hashCode()` Returns a hash code for this object instance.
    `boolean` | `isAfter(SerialDate other)` Returns true if this SerialDate represents the same date as the specified SerialDate.
    `boolean` | `isBefore(SerialDate other)` Returns true if this SerialDate represents an earlier date compared to the specified SerialDate.
    `boolean` | `isInRange(SerialDate d1, SerialDate d2)` Returns `true` if this `SerialDate` is within the specified range (INCLUSIVE).
    `boolean` | `isInRange(SerialDate d1, SerialDate d2, int include)` Returns true if this SerialDate is within the specified range (caller specifies whether or not the end-points are included).
    `boolean` | `isOn(SerialDate other)` Returns true if this SerialDate represents the same date as the specified SerialDate.
    `boolean` | `isOnOrAfter(SerialDate other)` Returns true if this SerialDate represents the same date as the specified SerialDate.
    `boolean` | `isOnOrBefore(SerialDate other)` Returns true if this SerialDate represents the same date as the specified SerialDate.
    `java.util.Date` | `toDate()` Returns a `java.util.Date` equivalent to this date.
    `int` | `toSerial()` 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).

    - ### Methods inherited from class org.jfree.date.SerialDate

      `addDays, addMonths, addYears, createInstance, createInstance, createInstance, getDescription, getEndOfCurrentMonth, getFollowingDayOfWeek, getFollowingDayOfWeek, getMonths, getMonths, getNearestDayOfWeek, getNearestDayOfWeek, getPreviousDayOfWeek, getPreviousDayOfWeek, isLeapYear, isValidMonthCode, isValidWeekdayCode, isValidWeekInMonthCode, lastDayOfMonth, leapYearCount, monthCodeToQuarter, monthCodeToString, monthCodeToString, relativeToString, setDescription, stringToMonthCode, stringToWeekdayCode, toString, weekdayCodeToString, weekInMonthToString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SpreadsheetDate

          public SpreadsheetDate(int day,
                                 int month,
                                 int year)

      Creates a new date instance.
      Parameters:
        `day` - the day (in the range 1 to 28/29/30/31).
        `month` - the month (in the range 1 to 12).
        `year` - the year (in the range 1900 to 9999).

    - #### SpreadsheetDate

          public SpreadsheetDate(int serial)

      Standard constructor - creates a new date object representing the specified day number (which should be in the range 2 to 2958465.
      Parameters:
        `serial` - the serial number for the day (range: 2 to 2958465).

  - ### Method Detail

    - #### toSerial

          public int toSerial()

      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).
      Specified by:
        `toSerial` in class `SerialDate`
      Returns:
        The serial number of this date.

    - #### toDate

          public java.util.Date toDate()

      Returns a `java.util.Date` equivalent to this date.
      Specified by:
        `toDate` in class `SerialDate`
      Returns:
        The date.

    - #### getYYYY

          public int getYYYY()

      Returns the year (assume a valid range of 1900 to 9999).
      Specified by:
        `getYYYY` in class `SerialDate`
      Returns:
        The year.

    - #### getMonth

          public int getMonth()

      Returns the month (January = 1, February = 2, March = 3).
      Specified by:
        `getMonth` in class `SerialDate`
      Returns:
        The month of the year.

    - #### getDayOfMonth

          public int getDayOfMonth()

      Returns the day of the month.
      Specified by:
        `getDayOfMonth` in class `SerialDate`
      Returns:
        The day of the month.

    - #### getDayOfWeek

          public int getDayOfWeek()

      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`.

      Specified by:
        `getDayOfWeek` in class `SerialDate`
      Returns:
        A code representing the day of the week.

    - #### equals

          public boolean equals(java.lang.Object object)

      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`.

      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `object` - the object to compare (`null` permitted).
      Returns:
        A boolean.

    - #### hashCode

          public int hashCode()

      Returns a hash code for this object instance.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        A hash code.

    - #### compare

          public int compare(SerialDate other)

      Returns the difference (in days) between this date and the specified 'other' date.
      Specified by:
        `compare` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        The difference (in days) between this date and the specified 'other' date.

    - #### compareTo

          public int compareTo(java.lang.Object other)

      Implements the method required by the Comparable interface.
      Parameters:
        `other` - the other object (usually another SerialDate).
      Returns:
        A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

    - #### isOn

          public boolean isOn(SerialDate other)

      Returns true if this SerialDate represents the same date as the specified SerialDate.
      Specified by:
        `isOn` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        `true` if this SerialDate represents the same date as the specified SerialDate.

    - #### isBefore

          public boolean isBefore(SerialDate other)

      Returns true if this SerialDate represents an earlier date compared to the specified SerialDate.
      Specified by:
        `isBefore` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        `true` if this SerialDate represents an earlier date compared to the specified SerialDate.

    - #### isOnOrBefore

          public boolean isOnOrBefore(SerialDate other)

      Returns true if this SerialDate represents the same date as the specified SerialDate.
      Specified by:
        `isOnOrBefore` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        `true` if this SerialDate represents the same date as the specified SerialDate.

    - #### isAfter

          public boolean isAfter(SerialDate other)

      Returns true if this SerialDate represents the same date as the specified SerialDate.
      Specified by:
        `isAfter` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        `true` if this SerialDate represents the same date as the specified SerialDate.

    - #### isOnOrAfter

          public boolean isOnOrAfter(SerialDate other)

      Returns true if this SerialDate represents the same date as the specified SerialDate.
      Specified by:
        `isOnOrAfter` in class `SerialDate`
      Parameters:
        `other` - the date being compared to.
      Returns:
        `true` if this SerialDate represents the same date as the specified SerialDate.

    - #### isInRange

          public boolean isInRange(SerialDate d1,
                                   SerialDate d2)

      Returns `true` if this `SerialDate` is within the specified range (INCLUSIVE). The date order of d1 and d2 is not important.
      Specified by:
        `isInRange` in class `SerialDate`
      Parameters:
        `d1` - a boundary date for the range.
        `d2` - the other boundary date for the range.
      Returns:
        A boolean.

    - #### isInRange

          public boolean isInRange(SerialDate d1,
                                   SerialDate d2,
                                   int include)

      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.
      Specified by:
        `isInRange` in class `SerialDate`
      Parameters:
        `d1` - one boundary date for the range.
        `d2` - a second boundary date for the range.
        `include` - a code that controls whether or not the start and end dates are included in the range.
      Returns:
        `true` if this SerialDate is within the specified range.