org.exolab.castor.types

Class DateTimeBase

public abstract class DateTimeBase extends Object implements Serializable

The base class for date/time XML Schema types.

The validation of the date/time fields is done in the set methods and follows the ISO8601 Date and Time Format.

Note: the castor date/time type are mutable, unlike the date/time types of the JDK in Java2. This is needed by the Marshalling framework.

Version: $Revision: 6309 $

Author: Arnaud Blandin

See Also: Date Time

Field Summary
static intEQUALS
static intGREATER_THAN
static intINDETERMINATE
Fields used for comparison methods
static intLESS_THAN
protected static StringWRONGLY_PLACED
Method Summary
voidaddDuration(Duration duration)

Adds a Duration to this Date/Time type as defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E). This version is using the algorithm defined in the document from W3C, next version may optimize it.

intcompareTo(DateTimeBase dateTime)

Compares two date/time data types.

protected booleanequal(DateTimeBase dateTime)

Returns true if the present instance of date/time type is equal to the parameter.

booleanequals(Object object)
Overrides the java.lang.Object#equals method
shortgetCentury()
shortgetDay()
shortgetHour()
shortgetMilli()
shortgetMinute()
shortgetMonth()
shortgetSeconds()
abstract short[]getValues()
returns an array of short with all the fields that describe a date/time type.
shortgetYear()
shortgetZoneHour()
shortgetZoneMinute()
inthashCode()
Overrides the java.lang.Object#hashcode method.
booleanisLeap(int year)
Returns true if the given year represents a leap year A specific year is a leap year if it is either evenly divisible by 400 OR evenly divisible by 4 and not evenly divisible by 100
booleanisNegative()
booleanisUTC()
Return true if this date/time type is UTC.
booleanisZoneNegative()
voidnormalize()

Normalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a timeZone is present but it is not Z then we convert the date/time datatype to Z using the addition operation defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E).

voidsetCentury(short century)
set the century field
voidsetDay(short day)
set the Day Field
voidsetHour(short hour)
set the hour field for this date/time type.
voidsetMilliSecond(short millisecond)
Sets the millisecond field for this date/time type
voidsetMinute(short minute)
set the minute field for this date/time type.
voidsetMonth(short month)
set the Month Field
voidsetNegative()
set the negative field to true
voidsetSecond(short second, short millsecond)
set the second field for this date/time type
voidsetSecond(short second)
Sets the second field for this date/time type
voidsetUTC()
set the UTC field.
abstract voidsetValues(short[] values)
Sets all the fields by reading the values in an array
voidsetYear(short year)
set the Year field Note: 0000 is not allowed
voidsetZone(short hour, short minute)
Sets the time zone fields for this date/time type.
voidsetZoneHour(short hour)
Sets the time zone hour field for this date/time type.
voidsetZoneMinute(short minute)
Sets the time zone minute field for this date/time type.
voidsetZoneNegative(boolean zoneNegative)
set the time zone negative field to true
CalendartoCalendar()
converts this Date/Time into a local java Calendar.
abstract DatetoDate()
Returns a java.util.Date that represents the XML Schema Date datatype

Field Detail

EQUALS

public static final int EQUALS

GREATER_THAN

public static final int GREATER_THAN

INDETERMINATE

public static final int INDETERMINATE
Fields used for comparison methods

LESS_THAN

public static final int LESS_THAN

WRONGLY_PLACED

protected static final String WRONGLY_PLACED

Method Detail

addDuration

public void addDuration(Duration duration)

Adds a Duration to this Date/Time type as defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E). This version is using the algorithm defined in the document from W3C, next version may optimize it.

Parameters: duration the duration to add

compareTo

public int compareTo(DateTimeBase dateTime)

Compares two date/time data types. The algorithm of comparison is defined in W3C XML Schema Recommendation (section 3.2.7.3)

The returned values can be:

Parameters: dateTime the dateTime to compare with the current instance.

Returns:

equal

protected boolean equal(DateTimeBase dateTime)

Returns true if the present instance of date/time type is equal to the parameter.

The equals relation is as defined in the W3C XML Schema Recommendation, part2.

Parameters: dateTime the date/time type to compare with the present instance

Returns: true if the present instance is equal to the parameter false if not

equals

public boolean equals(Object object)
Overrides the java.lang.Object#equals method

See Also: equals

getCentury

public short getCentury()

getDay

public short getDay()

getHour

public short getHour()

getMilli

public short getMilli()

getMinute

public short getMinute()

getMonth

public short getMonth()

getSeconds

public short getSeconds()

getValues

public abstract short[] getValues()
returns an array of short with all the fields that describe a date/time type.

Returns: an array of short with all the fields that describe a date/time type.

getYear

public short getYear()

getZoneHour

public short getZoneHour()

getZoneMinute

public short getZoneMinute()

hashCode

public int hashCode()
Overrides the java.lang.Object#hashcode method.

isLeap

public final boolean isLeap(int year)
Returns true if the given year represents a leap year A specific year is a leap year if it is either evenly divisible by 400 OR evenly divisible by 4 and not evenly divisible by 100

Parameters: year the year to test.

Returns: true if the given year represents a leap year

isNegative

public boolean isNegative()

isUTC

public boolean isUTC()
Return true if this date/time type is UTC. A date/time type is UTC if a 'Z' appears at the end of the lexical representation type or if it contains a time zone.

Returns: true if this recurringDuration type is UTC else false.

isZoneNegative

public boolean isZoneNegative()

normalize

public void normalize()

Normalizes a date/time datatype as defined in W3C XML Schema Recommendation document: if a timeZone is present but it is not Z then we convert the date/time datatype to Z using the addition operation defined in Adding Duration to dateTimes (W3C XML Schema, part 2 appendix E).

See Also: DateTimeBase

setCentury

public void setCentury(short century)
set the century field

Parameters: century the value to set up

setDay

public void setDay(short day)
set the Day Field

Parameters: day the value to set up Note a validation is done on the day field

setHour

public void setHour(short hour)
set the hour field for this date/time type.

Parameters: hour the hour to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the hour field is not allowed

setMilliSecond

public void setMilliSecond(short millisecond)
Sets the millisecond field for this date/time type

Parameters: millisecond the millisecond to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the second field is not allowed

setMinute

public void setMinute(short minute)
set the minute field for this date/time type.

Parameters: minute the minute to set.

Throws: OperationNotSupportedException this exception is thrown when changing the value of the minute field is not allowed

setMonth

public void setMonth(short month)
set the Month Field

Parameters: month the value to set up Note 1

setNegative

public void setNegative()
set the negative field to true

setSecond

public void setSecond(short second, short millsecond)
set the second field for this date/time type

Parameters: second the second to set millsecond the millisecond to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the second field is not allowed

setSecond

public void setSecond(short second)
Sets the second field for this date/time type

Parameters: second the second to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the second field is not allowed

setUTC

public void setUTC()
set the UTC field.

setValues

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

Parameters: values an array of shorts with the values

setYear

public void setYear(short year)
set the Year field Note: 0000 is not allowed

Parameters: year year to set up

setZone

public void setZone(short hour, short minute)
Sets the time zone fields for this date/time type. A call to this method means that the date/time type used is UTC.

Parameters: hour the time zone hour to set minute the time zone minute to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the time zone fields is not allowed

setZoneHour

public void setZoneHour(short hour)
Sets the time zone hour field for this date/time type. A call to this method means that the date/time type used is UTC.

Parameters: hour the time zone hour to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the time zone fields is not allowed

setZoneMinute

public void setZoneMinute(short minute)
Sets the time zone minute field for this date/time type. A call to this method means that the date/time type used is UTC.

Parameters: minute the time zone minute to set

Throws: OperationNotSupportedException this exception is thrown when changing the value of the time zone fields is not allowed

setZoneNegative

public void setZoneNegative(boolean zoneNegative)
set the time zone negative field to true

Throws: OperationNotSupportedException this exception is thrown when changing the time zone fields is not allowed

toCalendar

public Calendar toCalendar()
converts this Date/Time into a local java Calendar.

Returns: a local calendar representing this Date or Time

toDate

public abstract Date toDate()
Returns a java.util.Date that represents the XML Schema Date datatype
Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com