org.pf.util
Class SimpleDate

java.lang.Object
  extended by org.pf.util.SimpleDate
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class SimpleDate
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable, java.lang.Cloneable

This class represents a simple date. That means, it is not a timestamp like java.util.Date and it also starts with month 1 for January rather than with zero.

For convenience it also provides some commonly string representations.

Version:
1.0
Author:
M.Duchrow
See Also:
Serialized Form

Constructor Summary
SimpleDate()
          Initialize the new instance with default values (i.e. today's date).
SimpleDate(java.util.Date date)
          Initialize the new instance with a standard date object.
SimpleDate(java.util.GregorianCalendar gregorianCalendar)
          Initialize the new instance with a standard calendar.
SimpleDate(int year, int month, int day)
          Returns a Date object representing the given parameters.
 
Method Summary
 java.lang.String asBritishString()
          Returns the date in the format "dd/MM/yyyy" ("23/11/2002").
 java.util.Date asDate()
          Returns this date as Java Date object.
 java.lang.String asGermanString()
          Returns the date in the format "dd.MM.yyyy" ("23.11.2002").
 java.lang.String asISO8601String()
          Returns the date in the format "yyyy-MM-dd" ("2002-11-23").
 java.lang.String asSortString()
          Returns the date in the format "yyyyMMdd" ("20021123").
 java.lang.String asUSString()
          Returns the date in the format "MM/dd/yyyy" ("11/23/2002").
 java.lang.Object clone()
           
 int compareTo(java.lang.Object object)
           
 boolean equals(java.lang.Object object)
           
 int getDay()
          Returns the day in month as integer (1..31).
 int getMonth()
          Returns the month as integer (1 = January, ..., 12 = December).
 int getYear()
          Returns the year as integer (1900..3000).
 int hashCode()
           
static SimpleDate parseBritishDate(java.lang.String dateString)
          Creates a new SimpleDate from the given dateString which must conform to the format "dd/MM/yyyy".
static SimpleDate parseGermanDate(java.lang.String dateString)
          Creates a new SimpleDate from the given dateString which must conform to the format "dd.MM.yyyy".
static SimpleDate parseISO8601Date(java.lang.String dateString)
          Creates a new SimpleDate from the given dateString which must conform to the format "yyyy-MM-dd".
static SimpleDate parseSortDate(java.lang.String dateString)
          Creates a new SimpleDate from the given dateString which must conform to the format "yyyyMMdd".
static SimpleDate parseUSDate(java.lang.String dateString)
          Creates a new SimpleDate from the given dateString which must conform to the format "MM/dd/yyyy".
 java.lang.String toString()
          Returns the date in the format "yyyy-MM-dd" ("2002-11-23").
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleDate

public SimpleDate()
Initialize the new instance with default values (i.e. today's date).


SimpleDate

public SimpleDate(java.util.GregorianCalendar gregorianCalendar)
Initialize the new instance with a standard calendar.


SimpleDate

public SimpleDate(java.util.Date date)
Initialize the new instance with a standard date object.


SimpleDate

public SimpleDate(int year,
                  int month,
                  int day)
Returns a Date object representing the given parameters.

Parameters:
year - The year of the date to create
month - The month of the date to create (1-based, 1=January)
day - The day of the date to create
Method Detail

parseSortDate

public static SimpleDate parseSortDate(java.lang.String dateString)
                                throws java.text.ParseException
Creates a new SimpleDate from the given dateString which must conform to the format "yyyyMMdd".

Throws:
java.text.ParseException

parseGermanDate

public static SimpleDate parseGermanDate(java.lang.String dateString)
                                  throws java.text.ParseException
Creates a new SimpleDate from the given dateString which must conform to the format "dd.MM.yyyy".

Throws:
java.text.ParseException

parseBritishDate

public static SimpleDate parseBritishDate(java.lang.String dateString)
                                   throws java.text.ParseException
Creates a new SimpleDate from the given dateString which must conform to the format "dd/MM/yyyy".

Throws:
java.text.ParseException

parseUSDate

public static SimpleDate parseUSDate(java.lang.String dateString)
                              throws java.text.ParseException
Creates a new SimpleDate from the given dateString which must conform to the format "MM/dd/yyyy".

Throws:
java.text.ParseException

parseISO8601Date

public static SimpleDate parseISO8601Date(java.lang.String dateString)
                                   throws java.text.ParseException
Creates a new SimpleDate from the given dateString which must conform to the format "yyyy-MM-dd".

Throws:
java.text.ParseException

getYear

public int getYear()
Returns the year as integer (1900..3000).


getMonth

public int getMonth()
Returns the month as integer (1 = January, ..., 12 = December).


getDay

public int getDay()
Returns the day in month as integer (1..31).


asSortString

public java.lang.String asSortString()
Returns the date in the format "yyyyMMdd" ("20021123").


asISO8601String

public java.lang.String asISO8601String()
Returns the date in the format "yyyy-MM-dd" ("2002-11-23").


asGermanString

public java.lang.String asGermanString()
Returns the date in the format "dd.MM.yyyy" ("23.11.2002").


asBritishString

public java.lang.String asBritishString()
Returns the date in the format "dd/MM/yyyy" ("23/11/2002").


asUSString

public java.lang.String asUSString()
Returns the date in the format "MM/dd/yyyy" ("11/23/2002").


asDate

public java.util.Date asDate()
Returns this date as Java Date object.


toString

public java.lang.String toString()
Returns the date in the format "yyyy-MM-dd" ("2002-11-23").

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(java.lang.Object object)
Specified by:
compareTo in interface java.lang.Comparable

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException