|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openadaptor.util.DateHolder
public class DateHolder
DateHolder represents a straightforward date, with no time. It is used for holding dates in DataObjects, and converting from a string representation to numeric values for day, month, year and vice versa. It is immutable - once the DateHolder is created, the date in it cannot be changed.
It checks the validity of the date with which it is created, but it not encyclopaedic in its knowledge so does not handle the calendar changes which took place in the eighteenth century in England and earlier for Johnny Foreigner.
Some notes about the date values:
DateHolder has a standard text form (yyyy-mm-dd tz) which is used for serialising DateHolder values into DataObject XML and back again into DateHolders. The methods used to read and generate this form are DateHolder.parseDate() and toString(). If you wish to convert to and from arbitrary date strings, you should use java.text.SimpleDateFormat which uses Java Dates and Calendars, and convert the Dates to/from DateHolders. For an example of how to do this, look at the source code of DateFormatTransformer.
DateTimeHolder,
SimpleDateFormat,
Date,
TimeZone,
DateFormatTransformer,
Serialized Form| Field Summary | |
|---|---|
protected byte |
_date
Day of month 1..{28-31} |
protected byte |
_month
Month 0..11 |
protected java.lang.String |
_stringValue
cached string representation of the date |
protected java.lang.String |
_timezone
Deprecated. - Please start using _tz |
protected java.util.TimeZone |
_tz
TimeZone of the date |
protected static boolean |
_warnThisUse
Used to print a warning the first time that a deprecated constructor is used. |
protected short |
_year
Year YEAR_MIN..YEAR_MAX |
static java.util.TimeZone |
DEFAULT_TZ
The TimeZone used in DateHolder creation where no TimeZone is provided. |
static java.util.TimeZone |
GMT
Convenience GMT TimeZone reference |
static java.lang.String |
GMT_STR
Default (GMT) timezone string |
static short |
INVALID_DATE
Useful invalid date value |
static short |
INVALID_MONTH
Useful invalid month value |
static short |
INVALID_YEAR
Useful invalid year value |
static java.util.TimeZone |
LOCAL
Convenience Local (system) TimeZone reference |
(package private) static org.apache.log4j.Logger |
log
|
protected static int[] |
monthSizes
An array of twelve byte values representing the number of days in each month in a non-leap year |
protected boolean |
noTimezone
No timezone set, so do not output a timezone in toString() forms |
(package private) static long |
serialVersionUID
|
static short |
YEAR_MAX
Last handled year |
static short |
YEAR_MIN
First handled year |
| Constructor Summary | |
|---|---|
DateHolder()
Initialises a new DateHolder to the current date in the default timezone. |
|
DateHolder(java.util.Calendar cal)
Initialises a new DateHolder to the date specified. |
|
DateHolder(java.util.Date date)
Deprecated. Please use the constructors taking (Date, TimeZone) or (Calendar) parameters instead. |
|
DateHolder(java.util.Date date,
java.util.TimeZone tz)
Initialises a new DateHolder to the date specified. |
|
DateHolder(int year,
int month,
int date)
Deprecated. Please use the constructor taking (year,month,day,tz) parameters with an explicit TimeZone. |
|
DateHolder(int year,
int month,
int date,
java.lang.String timezone)
Deprecated. Please use the constructor taking (year,month,day,tz) parameters with an explicit TimeZone. |
|
DateHolder(int year,
int month,
int date,
java.util.TimeZone tz)
Initialises a new DateHolder to the date specified. |
|
DateHolder(java.lang.String str)
Constructs a DateHolder from a DOXML standard string definition. |
|
| Method Summary | |
|---|---|
java.util.Calendar |
asCalendar()
Returns the date/time value as a new java.util.Calendar object. |
java.util.Date |
asDate()
Returns the date value as a new java.util.Date object. |
int |
compareTo(java.lang.Object o)
Compares this date with the specified DateHolder for order. |
static int |
daysInMonth(int month,
int year)
Returns the number of days in the given month, allowing for leap years if year is a leap year. |
boolean |
equals(java.lang.Object o)
Returns true if the argument is a DateHolder containing the same date. |
int |
getDate()
Returns the day of the month, in the range 1..31. |
int |
getMonth()
Returns the month number, in the range 0..11. |
java.lang.String |
getTimezone()
Deprecated. Use TimeZones and getTimeZoneString() instead. |
java.util.TimeZone |
getTimeZone()
Returns the TimeZone. |
protected java.lang.String |
getTimezoneString()
Returns a string representing the timezone. |
int |
getTrueYear()
Returns the year value, an integer in the range YEAR_MIN..YEAR_MAX. |
int |
getYear()
Returns a java.util.Date compatible year value - year minus 1900. |
int |
hashCode()
Returns the hashcode for this date. |
static boolean |
isLeapYear(int year)
Returns true if year is a leap year |
static void |
main(java.lang.String[] args)
A thorough check of the date parsing and formatting routines, and a simple test of some illegal values |
static DateHolder |
parseDate(java.lang.String dateStr)
Reads a date string and attempts to create a DateHolder object for it. |
protected void |
set(java.util.Calendar cal)
For use in constructors only. |
java.lang.String |
toISOString()
Returns an ISO-8601 standard date of the form YYYY-MM-DD. |
java.lang.String |
toString()
Returns a standard format string representation of the date. |
static DateHolder |
valueOfDate(java.lang.String s)
Parses s as a Date string, and returns the DateHolder result. |
protected java.lang.String |
ymdToString()
Returns the year, month and day in YYYY-MM-DD format. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
static final long serialVersionUID
static org.apache.log4j.Logger log
public static final short YEAR_MIN
public static final short YEAR_MAX
public static final short INVALID_YEAR
public static final short INVALID_MONTH
public static final short INVALID_DATE
public static final java.lang.String GMT_STR
public static final java.util.TimeZone GMT
public static final java.util.TimeZone LOCAL
public static java.util.TimeZone DEFAULT_TZ
protected static final int[] monthSizes
protected static boolean _warnThisUse
protected final boolean noTimezone
protected byte _date
protected byte _month
protected short _year
YEAR_MIN,
YEAR_MAXprotected java.util.TimeZone _tz
protected java.lang.String _timezone
protected java.lang.String _stringValue
| Constructor Detail |
|---|
public DateHolder(java.lang.String str)
throws java.lang.Exception
str - DOXML standard string.
java.lang.ExceptiontoString()public DateHolder()
public DateHolder(java.util.Date date)
throws java.lang.Exception
date - Date value. Note that default constructor timezone
(currently GMT) is used.
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=12) or inconsistent (e.g. month=1(feb), date=30)
public DateHolder(java.util.Date date,
java.util.TimeZone tz)
throws java.lang.Exception
date - Date valuetz - TimeZone of date value; the system default is used if tz is null.
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=13) or inconsistent (e.g. month=1(feb), date=30)
public DateHolder(java.util.Calendar cal)
throws java.lang.Exception
cal - Calendar defining date and timezone.
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=12) or inconsistent (e.g. month=1(feb), date=30)
public DateHolder(int year,
int month,
int date)
throws java.lang.Exception
year - The year value, if less than 500 treated as year - 1900;
this is for java.util.Date compatibility.month - The month value, 0..11.date - The day value, 1..31
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=12) or inconsistent (e.g. month=1(feb), date=30)
public DateHolder(int year,
int month,
int date,
java.lang.String timezone)
throws java.lang.Exception
year - The year value, if less than 500 treated as year - 1900
this is for java.util.Date compatibility.month - The month value, 0..11date - The day value, 1..31timezone - Timezone string, or null (implies the default timezone).
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=12) or inconsistent (e.g. month=1(feb), date=30)
public DateHolder(int year,
int month,
int date,
java.util.TimeZone tz)
throws java.lang.Exception
year - The year value, if less than 500 treated as year - 1900
this is for java.util.Date compatibility.month - The month value, 0..11date - The day value, 1..31tz - Timezone string, or null.
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=12) or inconsistent (e.g. month=1(feb), date=30)| Method Detail |
|---|
public static DateHolder valueOfDate(java.lang.String s)
throws java.lang.IllegalArgumentException
s - Date string.
java.lang.IllegalArgumentException - If s cannot be parsed as a valid date.
public static boolean isLeapYear(int year)
throws java.lang.Exception
java.lang.Exception - If year is outside the range YEAR_MIN..YEAR_MAX
public static int daysInMonth(int month,
int year)
public static DateHolder parseDate(java.lang.String dateStr)
throws java.lang.Exception
dateStr - String containing text representation of date.
java.lang.Exception - If the string cannot be parsed as a valid date.toString()
protected void set(java.util.Calendar cal)
throws java.lang.Exception
cal - Calendar containing date/timezone properties.
java.lang.Exception - If any of the year, month, date values are invalid
(e.g. month=13) or inconsistent (e.g. month=1(feb), date=30)public int getTrueYear()
public int getYear()
public int getMonth()
public int getDate()
public java.lang.String getTimezone()
public java.util.TimeZone getTimeZone()
public java.util.Date asDate()
getTimeZone()public java.util.Calendar asCalendar()
getTimeZone()public java.lang.String toString()
The format used is: YYYY-MM-DD ZZ.
The timezone (ZZ) is optional, and if specified, will have an '@' prefix
if it is a Java TimeZone ID, otherwise it will be an arbitrary string.
For example 1997-02-14 is February 14, 1997 and
1997-02-14 @Europe/London
is February 14, 1997, in the Java 'Europe/London' timezone.
Spaces before the date and anything after the date (if there is no
timezone) are ignored.
If you wish to generate Date strings for consumption by non-openadaptor systems, convert the DateHolder into a Date (asDate()), and use java.text.SimpleDateFormat to do so.
The value returned is cached, as the date value is immutable.
toString in class java.lang.ObjectparseDate(java.lang.String)protected java.lang.String getTimezoneString()
public java.lang.String toISOString()
toString(),
ymdToString()protected java.lang.String ymdToString()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - Jave object for comparison
public int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(java.lang.Object o)
Date comparisons are transitive and commutative, but because of different timezone representations, Dates have a natural ordering that is inconsistent with equals.
compareTo in interface java.lang.Comparableo - the Object to be compared.
java.lang.ClassCastException - if the specified object's type prevents it
from being compared to this Object.public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||