org.exolab.castor.types
Class Date

java.lang.Object
  extended by org.exolab.castor.types.DateTimeBase
      extended by org.exolab.castor.types.Date
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Date
extends DateTimeBase

Describe an XML Schema Date.

The format is defined by W3C XML Schema Recommendation and ISO8601 i.e (-)CCYY-MM-DD(Z|(+|-)hh:mm)

Version:
$Revision: 7289 $
Author:
Arnaud Blandin, Edward Kuns
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.exolab.castor.types.DateTimeBase
EQUALS, GREATER_THAN, INDETERMINATE, LESS_THAN, MAX_TIME_ZONE_COMPARISON_OFFSET, WRONGLY_PLACED
 
Constructor Summary
Date()
          No-arg constructor.
Date(java.util.Date dateRef)
          This constructor is used to convert a java.util.Date into a new org.exolab.castor.types.Date.
Date(long dateAsLong)
          This constructor is used to convert a long value representing a Date to a new org.exolab.castor.types.Date instance.
Date(short[] values)
          Constructs a XML Schema Date instance given all the values of the different fields.
Date(java.lang.String date)
          Constructs a date from a string.
 
Method Summary
 short getHour()
           
 short getMilli()
           
 short getMinute()
           
 short getSeconds()
           
 short[] getValues()
          Returns an array of short with all the fields that describe this Date type.
 boolean hasHour()
           
 boolean hasMilli()
           
 boolean hasMinute()
           
 boolean hasSeconds()
           
static java.lang.Object parse(java.lang.String str)
          parse a String and convert it into an java.lang.Object
static Date parseDate(java.lang.String str)
          parse a String and convert it into a Date.
 void setHour(short hour)
          Sets the hour field for this date/time type.
 void setMilliSecond(short millisecond)
          Sets the millisecond field for this date/time type.
 void setMinute(short minute)
          set the minute field for this date/time type.
 void setSecond(short second)
          Sets the seconds field for this date/time type, not including the fractional seconds.
 void setValues(short[] values)
          Sets all the fields by reading the values in an array.
 java.util.Date toDate()
          Converts this Date into a local java.util.Date.
 long toLong()
          Converts this date into a long value.
 java.lang.String toString()
          convert this Date to a string The format is defined by W3C XML Schema recommendation and ISO8601 i.e (+|-)CCYY-MM-DD
 
Methods inherited from class org.exolab.castor.types.DateTimeBase
addDuration, appendDateString, appendTimeString, appendTimeZoneString, clone, compareTo, equal, equals, getCentury, getDay, getMonth, getYear, getZoneHour, getZoneMinute, hasCentury, hasDay, hashCode, hasIsNegative, hasMonth, hasYear, isLeap, isNegative, isUTC, isZoneNegative, normalize, parseDay, parseMonth, parseTime, parseTimeZone, parseYear, setCentury, setDateFormatTimeZone, setDateFormatTimeZone, setDay, setMonth, setNegative, setSecond, setUTC, setYear, setZone, setZoneHour, setZoneMinute, setZoneNegative, toCalendar
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Date

public Date()
No-arg constructor.


Date

public Date(short[] values)
Constructs a XML Schema Date instance given all the values of the different fields. By default a Date is not UTC and is local.

Parameters:
values - an array of shorts that represent the different fields of Time.

Date

public Date(long dateAsLong)
This constructor is used to convert a long value representing a Date to a new org.exolab.castor.types.Date instance.

Note : all the information concerning the time part of the java.util.Date is lost since a W3C Schema Date only represents CCYY-MM-YY

Parameters:
dateAsLong - Date represented in from of a long value.

Date

public Date(java.util.Date dateRef)
This constructor is used to convert a java.util.Date into a new org.exolab.castor.types.Date.

Note : all the information concerning the time part of the java.util.Date is lost since a W3C Schema Date only represents CCYY-MM-YY.

Parameters:
dateRef - the java.util.Date to use to construct a new org.exolab.castor.types.Date

Date

public Date(java.lang.String date)
     throws java.text.ParseException
Constructs a date from a string.

Parameters:
date - the string representing the date
Throws:
java.text.ParseException - a parse exception is thrown if the string to parse does not follow the right format (see the description of this class)
Method Detail

setValues

public void setValues(short[] values)
Sets all the fields by reading the values in an array.

If a Time Zone is specified, it has to be set by using setZone.

Specified by:
setValues in class DateTimeBase
Parameters:
values - an array of shorts with the values the array is supposed to be of length 4 and ordered like the following:
  • century
  • year
  • month
  • day

getValues

public short[] getValues()
Returns an array of short with all the fields that describe this Date type.

Note:the time zone is not included.

Specified by:
getValues in class DateTimeBase
Returns:
an array of short with all the fields that describe this Date type.

toDate

public java.util.Date toDate()
Converts this Date into a local java.util.Date.

Specified by:
toDate in class DateTimeBase
Returns:
a local date representing this Date.

toLong

public long toLong()
Converts this date into a long value.

Returns:
This date instance as a long value.

toString

public java.lang.String toString()
convert this Date to a string The format is defined by W3C XML Schema recommendation and ISO8601 i.e (+|-)CCYY-MM-DD

Overrides:
toString in class java.lang.Object
Returns:
a string representing this Date

parse

public static java.lang.Object parse(java.lang.String str)
                              throws java.text.ParseException
parse a String and convert it into an java.lang.Object

Parameters:
str - the string to parse
Returns:
an Object represented by the string
Throws:
java.text.ParseException - a parse exception is thrown if the string to parse does not follow the right format (see the description of this class)

parseDate

public static Date parseDate(java.lang.String str)
                      throws java.text.ParseException
parse a String and convert it into a Date.

Parameters:
str - the string to parse
Returns:
the Date represented by the string
Throws:
java.text.ParseException - a parse exception is thrown if the string to parse does not follow the right format (see the description of this class)

hasHour

public boolean hasHour()
Overrides:
hasHour in class DateTimeBase

getHour

public short getHour()
Overrides:
getHour in class DateTimeBase

setHour

public void setHour(short hour)
Description copied from class: DateTimeBase
Sets the hour field for this date/time type.

Overrides:
setHour in class DateTimeBase
Parameters:
hour - the hour to set

hasMinute

public boolean hasMinute()
Overrides:
hasMinute in class DateTimeBase

getMinute

public short getMinute()
Overrides:
getMinute in class DateTimeBase

setMinute

public void setMinute(short minute)
Description copied from class: DateTimeBase
set the minute field for this date/time type.

Overrides:
setMinute in class DateTimeBase
Parameters:
minute - the minute to set.

hasSeconds

public boolean hasSeconds()
Overrides:
hasSeconds in class DateTimeBase

getSeconds

public short getSeconds()
Overrides:
getSeconds in class DateTimeBase

setSecond

public void setSecond(short second)
Description copied from class: DateTimeBase
Sets the seconds field for this date/time type, not including the fractional seconds. Any fractional seconds previously set is unmodified.

Overrides:
setSecond in class DateTimeBase
Parameters:
second - the second to set

hasMilli

public boolean hasMilli()
Overrides:
hasMilli in class DateTimeBase

getMilli

public short getMilli()
Overrides:
getMilli in class DateTimeBase

setMilliSecond

public void setMilliSecond(short millisecond)
Description copied from class: DateTimeBase
Sets the millisecond field for this date/time type.

Overrides:
setMilliSecond in class DateTimeBase
Parameters:
millisecond - the millisecond to set


Copyright © 2011. All Rights Reserved.