Save This Page
Home » jcommon-1.0.13 » org.jfree.date » [javadoc | source]
org.jfree.date
abstract public class: SerialDate [javadoc | source]
java.lang.Object
   org.jfree.date.SerialDate

All Implemented Interfaces:
    Serializable, MonthConstants, Comparable

Direct Known Subclasses:
    SpreadsheetDate

An abstract class that defines our requirements for manipulating dates, without tying down a particular implementation.

Requirement 1 : match at least what Excel does for dates; Requirement 2 : the date represented by the class is immutable;

Why not just use java.util.Date? We will, when it makes sense. At times, java.util.Date can be *too* precise - it represents an instant in time, accurate to 1/1000th of a second (with the date itself depending on the time-zone). Sometimes we just want to represent a particular day (e.g. 21 January 2015) without concerning ourselves about the time of day, or the time-zone, or anything else. That's what we've defined SerialDate for.

You can call getInstance() to get a concrete subclass of SerialDate, without worrying about the exact implementation.

Field Summary
public static final  DateFormatSymbols DATE_FORMAT_SYMBOLS    Date format symbols. 
public static final  int SERIAL_LOWER_BOUND    The serial number for 1 January 1900. 
public static final  int SERIAL_UPPER_BOUND    The serial number for 31 December 9999. 
public static final  int MINIMUM_YEAR_SUPPORTED    The lowest year value supported by this date format. 
public static final  int MAXIMUM_YEAR_SUPPORTED    The highest year value supported by this date format. 
public static final  int MONDAY    Useful constant for Monday. Equivalent to java.util.Calendar.MONDAY. 
public static final  int TUESDAY    Useful constant for Tuesday. Equivalent to java.util.Calendar.TUESDAY. 
public static final  int WEDNESDAY    Useful constant for Wednesday. Equivalent to java.util.Calendar.WEDNESDAY. 
public static final  int THURSDAY    Useful constant for Thrusday. Equivalent to java.util.Calendar.THURSDAY. 
public static final  int FRIDAY    Useful constant for Friday. Equivalent to java.util.Calendar.FRIDAY. 
public static final  int SATURDAY    Useful constant for Saturday. Equivalent to java.util.Calendar.SATURDAY. 
public static final  int SUNDAY    Useful constant for Sunday. Equivalent to java.util.Calendar.SUNDAY. 
static final  int[] LAST_DAY_OF_MONTH    The number of days in each month in non leap years. 
static final  int[] AGGREGATE_DAYS_TO_END_OF_MONTH    The number of days in a (non-leap) year up to the end of each month. 
static final  int[] AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH    The number of days in a year up to the end of the preceding month. 
static final  int[] LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_MONTH    The number of days in a leap year up to the end of each month. 
static final  int[] LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH    The number of days in a leap year up to the end of the preceding month. 
public static final  int FIRST_WEEK_IN_MONTH    A useful constant for referring to the first week in a month. 
public static final  int SECOND_WEEK_IN_MONTH    A useful constant for referring to the second week in a month. 
public static final  int THIRD_WEEK_IN_MONTH    A useful constant for referring to the third week in a month. 
public static final  int FOURTH_WEEK_IN_MONTH    A useful constant for referring to the fourth week in a month. 
public static final  int LAST_WEEK_IN_MONTH    A useful constant for referring to the last week in a month. 
public static final  int INCLUDE_NONE    Useful range constant. 
public static final  int INCLUDE_FIRST    Useful range constant. 
public static final  int INCLUDE_SECOND    Useful range constant. 
public static final  int INCLUDE_BOTH    Useful range constant. 
public static final  int PRECEDING    Useful constant for specifying a day of the week relative to a fixed date. 
public static final  int NEAREST    Useful constant for specifying a day of the week relative to a fixed date. 
public static final  int FOLLOWING    Useful constant for specifying a day of the week relative to a fixed date. 
Constructor:
 protected SerialDate() 
Method from org.jfree.date.SerialDate Summary:
addDays,   addMonths,   addYears,   compare,   createInstance,   createInstance,   createInstance,   getDayOfMonth,   getDayOfWeek,   getDescription,   getEndOfCurrentMonth,   getFollowingDayOfWeek,   getFollowingDayOfWeek,   getMonth,   getMonths,   getMonths,   getNearestDayOfWeek,   getNearestDayOfWeek,   getPreviousDayOfWeek,   getPreviousDayOfWeek,   getYYYY,   isAfter,   isBefore,   isInRange,   isInRange,   isLeapYear,   isOn,   isOnOrAfter,   isOnOrBefore,   isValidMonthCode,   isValidWeekInMonthCode,   isValidWeekdayCode,   lastDayOfMonth,   leapYearCount,   monthCodeToQuarter,   monthCodeToString,   monthCodeToString,   relativeToString,   setDescription,   stringToMonthCode,   stringToWeekdayCode,   toDate,   toSerial,   toString,   weekInMonthToString,   weekdayCodeToString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.jfree.date.SerialDate Detail:
 public static SerialDate addDays(int days,
    SerialDate base) 
    Creates a new date by adding the specified number of days to the base date.
 public static SerialDate addMonths(int months,
    SerialDate base) 
    Creates a new date by adding the specified number of months to the base date.

    If the base date is close to the end of the month, the day on the result may be adjusted slightly: 31 May + 1 month = 30 June.

 public static SerialDate addYears(int years,
    SerialDate base) 
    Creates a new date by adding the specified number of years to the base date.
 abstract public int compare(SerialDate other)
    Returns the difference (in days) between this date and the specified 'other' date.

    The result is positive if this date is after the 'other' date and negative if it is before the 'other' date.

 public static SerialDate createInstance(int serial) 
    Factory method that returns an instance of some concrete subclass of SerialDate .
 public static SerialDate createInstance(Date date) 
    Factory method that returns an instance of a subclass of SerialDate.
 public static SerialDate createInstance(int day,
    int month,
    int yyyy) 
    Factory method that returns an instance of some concrete subclass of SerialDate .
 abstract public int getDayOfMonth()
    Returns the day of the month.
 abstract public int getDayOfWeek()
    Returns the day of the week.
 public String getDescription() 
    Returns the description that is attached to the date. It is not required that a date have a description, but for some applications it is useful.
 public SerialDate getEndOfCurrentMonth(SerialDate base) 
    Rolls the date forward to the last day of the month.
 public SerialDate getFollowingDayOfWeek(int targetDOW) 
    Returns the earliest date that falls on the specified day-of-the-week and is AFTER this date.
 public static SerialDate getFollowingDayOfWeek(int targetWeekday,
    SerialDate base) 
    Returns the earliest date that falls on the specified day-of-the-week and is AFTER the base date.
 abstract public int getMonth()
    Returns the month (January = 1, February = 2, March = 3).
 public static String[] getMonths() 
    Returns an array of month names.
 public static String[] getMonths(boolean shortened) 
    Returns an array of month names.
 public SerialDate getNearestDayOfWeek(int targetDOW) 
    Returns the nearest date that falls on the specified day-of-the-week.
 public static SerialDate getNearestDayOfWeek(int targetDOW,
    SerialDate base) 
    Returns the date that falls on the specified day-of-the-week and is CLOSEST to the base date.
 public SerialDate getPreviousDayOfWeek(int targetDOW) 
    Returns the latest date that falls on the specified day-of-the-week and is BEFORE this date.
 public static SerialDate getPreviousDayOfWeek(int targetWeekday,
    SerialDate base) 
    Returns the latest date that falls on the specified day-of-the-week and is BEFORE the base date.
 abstract public int getYYYY()
    Returns the year (assume a valid range of 1900 to 9999).
 abstract public boolean isAfter(SerialDate other)
    Returns true if this SerialDate represents the same date as the specified SerialDate.
 abstract public boolean isBefore(SerialDate other)
    Returns true if this SerialDate represents an earlier date compared to the specified SerialDate.
 abstract 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.
 abstract 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 date order of d1 and d2 is not important.
 public static boolean isLeapYear(int yyyy) 
    Determines whether or not the specified year is a leap year.
 abstract public boolean isOn(SerialDate other)
    Returns true if this SerialDate represents the same date as the specified SerialDate.
 abstract public boolean isOnOrAfter(SerialDate other)
    Returns true if this SerialDate represents the same date as the specified SerialDate.
 abstract public boolean isOnOrBefore(SerialDate other)
    Returns true if this SerialDate represents the same date as the specified SerialDate.
 public static boolean isValidMonthCode(int code) 
    Returns true if the supplied integer code represents a valid month.
 public static boolean isValidWeekInMonthCode(int code) 
    Returns true if the supplied integer code represents a valid week-in-the-month, and false otherwise.
 public static boolean isValidWeekdayCode(int code) 
    Returns true if the supplied integer code represents a valid day-of-the-week, and false otherwise.
 public static int lastDayOfMonth(int month,
    int yyyy) 
    Returns the number of the last day of the month, taking into account leap years.
 public static int leapYearCount(int yyyy) 
    Returns the number of leap years from 1900 to the specified year INCLUSIVE.

    Note that 1900 is not a leap year.

 public static int monthCodeToQuarter(int code) 
    Returns the quarter for the specified month.
 public static String monthCodeToString(int month) 
    Returns a string representing the supplied month.

    The string returned is the long form of the month name taken from the default locale.

 public static String monthCodeToString(int month,
    boolean shortened) 
    Returns a string representing the supplied month.

    The string returned is the long or short form of the month name taken from the default locale.

 public static String relativeToString(int relative) 
    Returns a string representing the supplied 'relative'.

    Need to find a better approach.

 public  void setDescription(String description) 
    Sets the description for the date.
 public static int stringToMonthCode(String s) 
    Converts a string to a month code.

    This method will return one of the constants JANUARY, FEBRUARY, ..., DECEMBER that corresponds to the string. If the string is not recognised, this method returns -1.

 public static int stringToWeekdayCode(String s) 
    Converts the supplied string to a day of the week.
 abstract public Date toDate()
    Returns a java.util.Date. Since java.util.Date has more precision than SerialDate, we need to define a convention for the 'time of day'.
 abstract 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).
 public String toString() 
    Converts the date to a string.
 public static String weekInMonthToString(int count) 
    Returns a string corresponding to the week-in-the-month code.

    Need to find a better approach.

 public static String weekdayCodeToString(int weekday) 
    Returns a string representing the supplied day-of-the-week.

    Need to find a better approach.