wt.util
Class WrappedDate

java.lang.Object
  extended byjava.util.Date
      extended byjava.sql.Date
          extended bywt.util.WrappedDate
All Implemented Interfaces:
Cloneable, Comparable, Serializable

public class WrappedDate
extends Date

This class is a wrapper around java.sql.Date that corrects time zone related errors and dependencies that prevent java.sql.Date from fulfilling its contract:

java.sql.Date is a thin wrapper around java.util.Date that allows JDBC to identify this as a SQL DATE value. It adds formatting and parsing operations to support the JDBC escape syntax for date values.

See Also:
Serialized Form

Nested Class Summary
private static class WrappedDate.StandardCalendar
           
 
Field Summary
private  WrappedDate.StandardCalendar cal
           
private static String timezoneId
           
 
Fields inherited from class java.sql.Date
 
Fields inherited from class java.util.Date
 
Constructor Summary
WrappedDate(int year, int month, int date)
          Deprecated. Use WrappedDate(long)
WrappedDate(long date)
          Constructs a Date using a milliseconds time value.
 
Method Summary
 boolean after(Date when)
          Tests if this date is after the specified date.
 boolean before(Date when)
          Tests if this date is before the specified date.
 boolean equals(Object obj)
          Compares two dates.
 int getDate()
          Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH).
 int getDay()
          Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).
 int getMonth()
          Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).
 long getTime()
          Returns the number of milliseconds elapsed between January 1, 1970, 00:00:00 GMT and 00:00:00 GMT of this date.
 int getTimezoneOffset()
          Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET).
 int getYear()
          Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.
private  void readObject(ObjectInputStream s)
          readObject is called to restore a date from the stream.
 void setDate(int date)
          Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date).
 void setMonth(int month)
          Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.MONTH, int month).
 void setTime(long time)
          Sets a Date using a milliseconds time value.
 void setYear(int year)
          Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR, year + 1900).
 String toString()
          Formats a date in JDBC date escape format.
static Date valueOf(String s)
          Converts a string in JDBC date escape format to a Date value.
private  void writeObject(ObjectOutputStream s)
          writeObject is called to save the Date to a stream.
 
Methods inherited from class java.sql.Date
getHours, getMinutes, getSeconds, setHours, setMinutes, setSeconds
 
Methods inherited from class java.util.Date
clone, compareTo, compareTo, hashCode, parse, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

timezoneId

private static String timezoneId

cal

private transient WrappedDate.StandardCalendar cal
Constructor Detail

WrappedDate

public WrappedDate(int year,
                   int month,
                   int date)
Deprecated. Use WrappedDate(long)

Constructs a Date independent of time zone.

Parameters:
year - year-1900
month - 0 to 11

WrappedDate

public WrappedDate(long date)
Constructs a Date using a milliseconds time value. Note that the resulting Date will be the same for any value representing a time between 00:00:00.000 and 23:59:59.999 GMT on a given date.

Parameters:
date - milliseconds since January 1, 1970, 00:00:00 GMT
Method Detail

getYear

public int getYear()
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.

Returns the year represented by this date, minus 1900.

Returns:
the year represented by this date, minus 1900
Since:
JDK1.0
See Also:
Calendar

setYear

public void setYear(int year)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR, year + 1900).

Sets the year of this date to be the specified value plus 1900.

Parameters:
year - the year value
Since:
JDK1.0
See Also:
Calendar

getMonth

public int getMonth()
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.MONTH).

Returns the month represented by this date. The value returned is between 0 and 11, with the value 0 representing January.

Returns:
the month represented by this date
Since:
JDK1.0
See Also:
Calendar

setMonth

public void setMonth(int month)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.MONTH, int month).

Sets the month of this date to the specified value.

Parameters:
month - the month value between 0-11
Since:
JDK1.0
See Also:
Calendar

getDate

public int getDate()
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH).

Returns the day of the month represented by this date. The value returned is between 1 and 31.

Returns:
the day of the month represented by this date
Since:
JDK1.0
See Also:
Calendar

setDate

public void setDate(int date)
Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date).

Sets the day of the month of this date to the specified value.

Parameters:
date - the day of the month value between 1-31
Since:
JDK1.0
See Also:
Calendar

getDay

public int getDay()
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).

Returns the day of the week represented by this date. The value returned is between 0 and 6, where 0 represents Sunday.

Returns:
the day of the week represented by this date
Since:
JDK1.0
See Also:
Calendar

getTime

public long getTime()
Returns the number of milliseconds elapsed between January 1, 1970, 00:00:00 GMT and 00:00:00 GMT of this date.

Returns:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date
Since:
JDK1.0

setTime

public void setTime(long time)
Sets a Date using a milliseconds time value.


before

public boolean before(Date when)
Tests if this date is before the specified date. The result is true if the specified date represents any point in time prior to 00:00:00.000 GMT on this date.

Parameters:
when - a date
Returns:
true if this date is before the argument date; false otherwise.
Since:
JDK1.0

after

public boolean after(Date when)
Tests if this date is after the specified date. The result is true if the specified date represents any point in time after 23:59:59.999 GMT on this date.

Parameters:
when - a date
Returns:
true if this date is after the argument date; false otherwise.
Since:
JDK1.0

equals

public boolean equals(Object obj)
Compares two dates. The result is true if and only if the argument is not null and is a java.util.Date object that represents any point in time between 00:00:00.000 and 23:59:59.999 GMT inclusive on the same date as this object.

Parameters:
obj - the object to compare with
Returns:
true if the objects are the same; false otherwise.
Since:
JDK1.0

valueOf

public static Date valueOf(String s)
Converts a string in JDBC date escape format to a Date value.

Parameters:
s - date in format "yyyy-mm-dd"
Returns:
corresponding Date

toString

public String toString()
Formats a date in JDBC date escape format.

Returns:
a String in yyyy-mm-dd format

getTimezoneOffset

public int getTimezoneOffset()
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET).

Returns the local time-zone offset. The time-zone offset is the number of minutes that must be added to GMT to give the local time zone. This value includes the correction, if necessary, for daylight saving time. Since wt.util.Date is time zone independent, the result returned is universally zero by convention.

Returns:
zero
Since:
JDK1.0
See Also:
Calendar, TimeZone

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
writeObject is called to save the Date to a stream. The UTC time (always midnight of the given date) is written to the stream as a long.

Throws:
IOException

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
readObject is called to restore a date from the stream. The UTC time (always midnight of the given date) is read and the date set from it.

Throws:
IOException
ClassNotFoundException