javax.xml.datatype
Class XMLGregorianCalendar

java.lang.Object
  extended by javax.xml.datatype.XMLGregorianCalendar
All Implemented Interfaces:
Cloneable, Serializable

public class XMLGregorianCalendar
extends Object
implements Serializable, Cloneable

Representation for W3C XML Schema 1.0 date/time datatypes. Specifically, these date/time datatypes are dateTime, time, date, gYearMonth, gMonthDay, gYear gMonth and gDay defined in the XML Namespace "http://www.w3.org/2001/XMLSchema". These datatypes are normatively defined in W3C XML Schema 1.0 Part 2, Section 3.2.7-14.

The table below defines the mapping between XML Schema 1.0 date/time datatype fields and this class' fields. It also summarizes the value constraints for the date and time fields defined in W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats.

Date/time datatype field mapping between XML Schema 1.0 and Java representation
XML Schema 1.0
datatype
field
Related
XMLGregorianCalendar
Accessor(s)
Value Range
year getYear() + getEon() or
getEonAndYear()
getYear() is a value between -(10^9-1) to (10^9)-1 or FIELD_UNDEFINED.
getEon() is high order year value in billion of years.
getEon() has values greater than or equal to (10^9) or less than or equal to -(10^9). A value of null indicates field is undefined.
month getMonth() 1 to 12 or FIELD_UNDEFINED
day getDay() Independent of month, max range is 1 to 31 or FIELD_UNDEFINED.
The normative value constraint stated relative to month field's value is in W3C XML Schema 1.0 Part 2, Appendix D.
hour getHour() 0 to 23 or FIELD_UNDEFINED
minute getMinute() 0 to 59 or FIELD_UNDEFINED
second getSecond() + getMillisecond()/1000 or
getSecond() + getFractionalSecond()
getSecond() from 0 to 60 or FIELD_UNDEFINED.
(Note: 60 only allowable for leap second.)

getMillisecond() allows only for millisecond precision, is optional and has a value of FIELD_UNDEFINED when it is undefined.
getFractionalSecond() allows for infinite precision over the range from 0.0 to 1.0.
FractionalSecond is optional and has a value of null when it is undefined.
timezone getTimezone() Number of minutes or FIELD_UNDEFINED. Value range from -14 hours (-14 * 60 minutes) to 14 hours (14 * 60 minutes) exclusive.

All maximum value space constraints listed for the fields in the table above are checked by factory methods, setter methods and parse methods of this class. IllegalArgumentException is thrown when parameter's value is outside the maximum value constraint for the field. Validation checks, for example, whether days in month should be limited to 29, 30 or 31 days, that are dependent on the values of other fields are not checked by these methods.

The following operations are defined for this class:

Since:
1.5
See Also:
Duration, Serialized Form

Field Summary
static int APRIL
          Value for fourth month of year.
static int AUGUST
          Value for eighth month of year.
static QName DATE
          Fully qualified name for W3C XML Schema 1.0 datatype date.
static QName DATETIME
          Fully qualified name for W3C XML Schema 1.0 datatype dateTime.
static int DECEMBER
          Value for twelve month of year.
static int EQUAL
          Partial order relation comparison result.
static int FEBRUARY
          Value for second month of year.
static int FIELD_UNDEFINED
          Designation that an "int" field is not set.
static QName GDAY
          Fully qualified name for W3C XML Schema 1.0 datatype gDay.
static QName GMONTH
          Fully qualified name for W3C XML Schema 1.0 datatype gMonth.
static QName GMONTHDAY
          Fully qualified name for W3C XML Schema 1.0 datatype gMonthDay.
static int GREATER
          Partial order relation comparison result.
static QName GYEAR
          Fully qualified name for W3C XML Schema 1.0 datatype gYear.
static QName GYEARMONTH
          Fully qualified name for W3C XML Schema 1.0 datatype gYearMonth.
static int INDETERMINATE
          Partial order relation comparison result.
static int JANUARY
          Value for first month of year.
static int JULY
          Value for seventh month of year.
static int JUNE
          Value for sixth month of year.
static XMLGregorianCalendar LEAP_YEAR_DEFAULT
          Use as a template for default field values when converting to a java.util.GregorianCalendar, set to a leap year date of January 1, 0400 at midnight.
static int LESSER
          Partial order relation comparison result.
static int MARCH
          Value for third month of year.
static int MAX_TIMEZONE_OFFSET
          W3C XML Schema max timezone offset is -14:00.
static int MAY
          Value for fifth month of year.
static int MIN_TIMEZONE_OFFSET
          W3C XML Schema min timezone offset is +14:00.
static int NOVEMBER
          Value for eleven month of year.
static int OCTOBER
          Value for tenth month of year.
static int SEPTEMBER
          Value for ninth month of year.
static QName TIME
          Fully qualified name for W3C XML Schema 1.0 datatype time.
 
Constructor Summary
XMLGregorianCalendar()
          Create an instance with all date/time datatype fields set to FIELD_UNDEFINED or null respectively.
 
Method Summary
 void add(Duration duration)
          Add duration to this instance.<\p>
 void clear()
          Unset all fields to undefined.
 Object clone()
          Creates and returns a copy of this object.
static int compare(XMLGregorianCalendar lhs, XMLGregorianCalendar rhs)
          Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.
static XMLGregorianCalendar createDate(int year, int month, int day, int timezone)
          Create a Java representation of XML Schema builtin datatype date or g*.
static XMLGregorianCalendar createDateTime(BigInteger year, int month, int day, int hours, int minutes, int seconds, BigDecimal fractionalSecond, int timezone)
          Create a Java representation of XML Schema builtin datatype dateTime.
static XMLGregorianCalendar createDateTime(int year, int month, int day, int hour, int minute, int second)
          Create a Java instance of XML Schema builtin datatype dateTime.
static XMLGregorianCalendar createDateTime(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds, int timezone)
          Create a Java representation of XML Schema builtin datatype dateTime.
static XMLGregorianCalendar createTime(int hours, int minutes, int seconds, BigDecimal fractionalSecond, int timezone)
          Create a Java instance of XML Schema builtin datatype time.
static XMLGregorianCalendar createTime(int hours, int minutes, int seconds, int timezone)
          Create a Java instance of XML Schema builtin datatype time.
static XMLGregorianCalendar createTime(int hours, int minutes, int seconds, int milliseconds, int timezone)
          Create a Java instance of XML Schema builtin datatype time.
 boolean equals(Object obj)
          Indicates whether parameter obj is "equal to" this one.
static XMLGregorianCalendar fromGregorianCalendar(GregorianCalendar cal)
          Convert a java.util.GregorianCalendar to XML Schema 1.0 representation.
 int getDay()
          Return day in month or FIELD_UNDEFINED.
 BigInteger getEon()
          Get the eons of the year.
 BigInteger getEonAndYear()
          Return XML Schema 1.0 dateTime datatype field for year.
 BigDecimal getFractionalSecond()
          Return fractional seconds.
 int getHour()
          Return hours or FIELD_UNDEFINED.
 int getMillisecond()
          Return milliseconds or FIELD_UNDEFINED.<\p>
 int getMinute()
          Return minutes or FIELD_UNDEFINED.<\p> Returns FIELD_UNDEFINED if this field is not defined.
 int getMonth()
          Return number of month or FIELD_UNDEFINED.
 int getSecond()
          Return seconds or FIELD_UNDEFINED.<\p>
 int getTimezone()
          Return timezone offset in minutes or FIELD_UNDEFINED if this optional field is not defined.
 QName getXMLSchemaType()
          Return the name of the XML Schema date/time type that this instance maps to.
 int getYear()
          Return low order component XML Schema 1.0 dataTime datatype field for year or FIELD_UNDEFINED.
 int hashCode()
          Returns a hash code consistent with the definition of the equals method.
 boolean isValid()
          Validate instance by getXMLSchemaType() constraints.
static XMLGregorianCalendar parse(String lexicalRepresentation)
          Constructs a new XMLGregorianCalendar object by parsing its lexical string representation as defined in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation.
 void setDay(int day)
          Set days in month.
 void setMonth(int month)
          Set month.
 void setTime(int hour, int minute, int second)
          Set time as one unit.
 void setTime(int hour, int minute, int second, BigDecimal fractional)
          Set time as one unit, including the optional infinite precison fractional seconds.
 void setTime(int hour, int minute, int second, int millisecond)
          Set time as one unit, including optional milliseconds.
 void setTimezone(int offset)
          Set the number of minutes in the timezone offset.
 void setYear(BigInteger year)
          Set low and high order component of XSD dateTime year field.
 void setYear(int year)
          Set year of XSD dateTime year field.
 GregorianCalendar toGregorianCalendar()
          Convert this to java.util.GregorianCalendar.
 GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)
          Convert this along with provided parameters to java.util.GregorianCalendar instance.
 String toXMLFormat()
          Return the lexical representation of this instance.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JANUARY

public static final int JANUARY
Value for first month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

FEBRUARY

public static final int FEBRUARY
Value for second month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

MARCH

public static final int MARCH
Value for third month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

APRIL

public static final int APRIL
Value for fourth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

MAY

public static final int MAY
Value for fifth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

JUNE

public static final int JUNE
Value for sixth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

JULY

public static final int JULY
Value for seventh month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

AUGUST

public static final int AUGUST
Value for eighth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

SEPTEMBER

public static final int SEPTEMBER
Value for ninth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

OCTOBER

public static final int OCTOBER
Value for tenth month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

NOVEMBER

public static final int NOVEMBER
Value for eleven month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

DECEMBER

public static final int DECEMBER
Value for twelve month of year.

See Also:
getMonth(), setMonth(int), Constant Field Values

FIELD_UNDEFINED

public static final int FIELD_UNDEFINED
Designation that an "int" field is not set.

See Also:
Constant Field Values

LESSER

public static final int LESSER
Partial order relation comparison result.

See Also:
compare(XMLGregorianCalendar, XMLGregorianCalendar), Constant Field Values

EQUAL

public static final int EQUAL
Partial order relation comparison result.

See Also:
compare(XMLGregorianCalendar, XMLGregorianCalendar), Constant Field Values

GREATER

public static final int GREATER
Partial order relation comparison result.

See Also:
compare(XMLGregorianCalendar, XMLGregorianCalendar), Constant Field Values

INDETERMINATE

public static final int INDETERMINATE
Partial order relation comparison result.

See Also:
compare(XMLGregorianCalendar, XMLGregorianCalendar), Constant Field Values

LEAP_YEAR_DEFAULT

public static final XMLGregorianCalendar LEAP_YEAR_DEFAULT

Use as a template for default field values when converting to a java.util.GregorianCalendar, set to a leap year date of January 1, 0400 at midnight.

See Also:
toGregorianCalendar(TimeZone, Locale, XMLGregorianCalendar)

DATETIME

public static final QName DATETIME

Fully qualified name for W3C XML Schema 1.0 datatype dateTime.


TIME

public static final QName TIME

Fully qualified name for W3C XML Schema 1.0 datatype time.


DATE

public static final QName DATE

Fully qualified name for W3C XML Schema 1.0 datatype date.


GYEARMONTH

public static final QName GYEARMONTH

Fully qualified name for W3C XML Schema 1.0 datatype gYearMonth.


GMONTHDAY

public static final QName GMONTHDAY

Fully qualified name for W3C XML Schema 1.0 datatype gMonthDay.


GYEAR

public static final QName GYEAR

Fully qualified name for W3C XML Schema 1.0 datatype gYear.


GMONTH

public static final QName GMONTH

Fully qualified name for W3C XML Schema 1.0 datatype gMonth.


GDAY

public static final QName GDAY

Fully qualified name for W3C XML Schema 1.0 datatype gDay.


MAX_TIMEZONE_OFFSET

public static final int MAX_TIMEZONE_OFFSET
W3C XML Schema max timezone offset is -14:00. Zone offset is in minutes.

See Also:
Constant Field Values

MIN_TIMEZONE_OFFSET

public static final int MIN_TIMEZONE_OFFSET
W3C XML Schema min timezone offset is +14:00. Zone offset is in minutes.

See Also:
Constant Field Values
Constructor Detail

XMLGregorianCalendar

public XMLGregorianCalendar()

Create an instance with all date/time datatype fields set to FIELD_UNDEFINED or null respectively.

Method Detail

createDateTime

public static XMLGregorianCalendar createDateTime(BigInteger year,
                                                  int month,
                                                  int day,
                                                  int hours,
                                                  int minutes,
                                                  int seconds,
                                                  BigDecimal fractionalSecond,
                                                  int timezone)

Create a Java representation of XML Schema builtin datatype dateTime. All possible fields are specified for this factory method.

Parameters:
year - represents both high-order eons and low-order year.
month - of dateTime
day - of dateTime
hours - of dateTime
minutes - of dateTime
seconds - of dateTime
fractionalSecond - value of null indicates optional field is absent.
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createDateTime

public static XMLGregorianCalendar createDateTime(int year,
                                                  int month,
                                                  int day,
                                                  int hour,
                                                  int minute,
                                                  int second)

Create a Java instance of XML Schema builtin datatype dateTime.

Parameters:
year - represents both high-order eons and low-order year.
month - of dateTime
day - of dateTime
hour - of dateTime
minute - of dateTime
second - of dateTime
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createDateTime

public static XMLGregorianCalendar createDateTime(int year,
                                                  int month,
                                                  int day,
                                                  int hours,
                                                  int minutes,
                                                  int seconds,
                                                  int milliseconds,
                                                  int timezone)

Create a Java representation of XML Schema builtin datatype dateTime. All possible fields are specified for this factory method.

Parameters:
year - represents low-order year.
month - of dateTime
day - of dateTime
hours - of dateTime
minutes - of dateTime
seconds - of dateTime
milliseconds - of dateTime. FIELD_UNDEFINED indicates optional field is not set.
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createDate

public static XMLGregorianCalendar createDate(int year,
                                              int month,
                                              int day,
                                              int timezone)

Create a Java representation of XML Schema builtin datatype date or g*.

For example, an instance of gYear can be created invoking this factory with month and day parameters set to FIELD_UNDEFINED.

Parameters:
year - of XMLGregorianCalendar to be created.
month - of XMLGregorianCalendar to be created.
day - of XMLGregorianCalendar to be created.
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createTime

public static XMLGregorianCalendar createTime(int hours,
                                              int minutes,
                                              int seconds,
                                              int timezone)
Create a Java instance of XML Schema builtin datatype time.

Parameters:
hours - number of hours
minutes - number of minutes
seconds - number of seconds
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createTime

public static XMLGregorianCalendar createTime(int hours,
                                              int minutes,
                                              int seconds,
                                              BigDecimal fractionalSecond,
                                              int timezone)

Create a Java instance of XML Schema builtin datatype time.

Parameters:
hours - number of hours
minutes - number of minutes
seconds - number of seconds
fractionalSecond - value of null indicates that this optional field is not set.
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

createTime

public static XMLGregorianCalendar createTime(int hours,
                                              int minutes,
                                              int seconds,
                                              int milliseconds,
                                              int timezone)

Create a Java instance of XML Schema builtin datatype time.

Parameters:
hours - number of hours
minutes - number of minutes
seconds - number of seconds
milliseconds - number of milliseconds
timezone - offset in minutes. FIELD_UNDEFINED indicates optional field is not set.
Returns:
XMLGregorianCalendar created from parameter values.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
FIELD_UNDEFINED

getEon

public BigInteger getEon()

Get the eons of the year. null if this optional part of the year field is not defined.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:
eon of this XMLGregorianCalendar.
See Also:
getYear(), getEonAndYear()

getYear

public int getYear()

Return low order component XML Schema 1.0 dataTime datatype field for year or FIELD_UNDEFINED.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:
year of this XMLGregorianCalendar.
See Also:
getEon(), getEonAndYear()

getEonAndYear

public BigInteger getEonAndYear()

Return XML Schema 1.0 dateTime datatype field for year.

Value constraints for this value are summarized in year field of date/time field mapping table.

Returns:
sum of eon and BigInteger.valueOf(year) when both fields are defined. When only year is defined, return it. When both eon and year are not defined, return null.
See Also:
getEon(), getYear()

getMonth

public int getMonth()

Return number of month or FIELD_UNDEFINED.

Value constraints for this value are summarized in month field of date/time field mapping table.

Returns:
year of this XMLGregorianCalendar.

getDay

public int getDay()
Return day in month or FIELD_UNDEFINED.

Value constraints for this value are summarized in day field of date/time field mapping table.

See Also:
setDay(int)

getTimezone

public int getTimezone()
Return timezone offset in minutes or FIELD_UNDEFINED if this optional field is not defined.

Value constraints for this value are summarized in timezone field of date/time field mapping table.

See Also:
setTimezone(int)

getHour

public int getHour()
Return hours or FIELD_UNDEFINED. Returns FIELD_UNDEFINED if this field is not defined.

Value constraints for this value are summarized in hour field of date/time field mapping table.

See Also:
setTime(int, int, int)

getMinute

public int getMinute()
Return minutes or FIELD_UNDEFINED.<\p> Returns FIELD_UNDEFINED if this field is not defined.

Value constraints for this value are summarized in minute field of date/time field mapping table.

See Also:
setTime(int, int, int)

getSecond

public int getSecond()

Return seconds or FIELD_UNDEFINED.<\p>

Returns FIELD_UNDEFINED if this field is not defined.

Value constraints for this value are summarized in second field of date/time field mapping table.

Returns:
Second of this XMLGregorianCalendar.
See Also:
getFractionalSecond(), setTime(int, int, int)

getMillisecond

public int getMillisecond()

Return milliseconds or FIELD_UNDEFINED.<\p>

Returns FIELD_UNDEFINED if this field is not defined.<\p>

Value constraints for this value are summarized in second field of date/time field mapping table.

Returns:
Millisecond of this XMLGregorianCalendar.
See Also:
getFractionalSecond(), setTime(int, int, int)

getFractionalSecond

public BigDecimal getFractionalSecond()

Return fractional seconds.

null is returned when this optional field is not defined.

Value constraints are detailed in second field of date/time field mapping table.

Returns:
fractional seconds of this XMLGregorianCalendar.
See Also:
getSecond(), setTime(int, int, int, BigDecimal)

setYear

public void setYear(BigInteger year)

Set low and high order component of XSD dateTime year field.

Unset this field by invoking the setter with a parameter value of null.

Parameters:
year - value constraints summarized in year field of date/time field mapping table.
Throws:
IllegalArgumentException - if year parameter is outside value constraints for the field as specified in date/time field mapping table.

setYear

public void setYear(int year)

Set year of XSD dateTime year field.

Unset this field by invoking the setter with a parameter value of FIELD_UNDEFINED.

Parameters:
year - value constraints are summarized in year field of date/time field mapping table. If year is FIELD_UNDEFINED, then eon is set to null.

setMonth

public void setMonth(int month)

Set month.

Unset this field by invoking the setter with a parameter value of FIELD_UNDEFINED.

Parameters:
month - value constraints summarized in month field of date/time field mapping table.
Throws:
IllegalArgumentException - if month parameter is outside value constraints for the field as specified in date/time field mapping table.

setDay

public void setDay(int day)

Set days in month.

Unset this field by invoking the setter with a parameter value of FIELD_UNDEFINED.

Parameters:
day - value constraints summarized in day field of date/time field mapping table.
Throws:
IllegalArgumentException - if day parameter is outside value constraints for the field as specified in date/time field mapping table.

setTimezone

public void setTimezone(int offset)

Set the number of minutes in the timezone offset.

Unset this field by invoking the setter with a parameter value of FIELD_UNDEFINED.

Parameters:
offset - value constraints summarized in timezone field of date/time field mapping table.
Throws:
IllegalArgumentException - if offset parameter is outside value constraints for the field as specified in date/time field mapping table.

setTime

public void setTime(int hour,
                    int minute,
                    int second)

Set time as one unit.

Parameters:
hour - value constraints are summarized in hour field of date/time field mapping table.
minute - value constraints are summarized in minute field of date/time field mapping table.
second - value constraints are summarized in second field of date/time field mapping table.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.
See Also:
setTime(int, int, int, BigDecimal)

setTime

public void setTime(int hour,
                    int minute,
                    int second,
                    BigDecimal fractional)

Set time as one unit, including the optional infinite precison fractional seconds.

Parameters:
hour - value constraints are summarized in hour field of date/time field mapping table.
minute - value constraints are summarized in minute field of date/time field mapping table.
second - value constraints are summarized in second field of date/time field mapping table.
fractional - value of null indicates this optional field is not set.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.

setTime

public void setTime(int hour,
                    int minute,
                    int second,
                    int millisecond)

Set time as one unit, including optional milliseconds.

Parameters:
hour - value constraints are summarized in hour field of date/time field mapping table.
minute - value constraints are summarized in minute field of date/time field mapping table.
second - value constraints are summarized in second field of date/time field mapping table.
millisecond - value of FIELD_UNDEFINED indicates this optional field is not set.
Throws:
IllegalArgumentException - if any parameter is outside value constraints for the field as specified in date/time field mapping table.

compare

public static int compare(XMLGregorianCalendar lhs,
                          XMLGregorianCalendar rhs)

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.

xsd:dateTime datatype field mapping to accessors of this class are defined in date/time field mapping table.

Parameters:
lhs - instance of XMLGregorianCalendar to compare
rhs - instance of XMLGregorianCalendar to compare
Returns:
the relationship between lhs and rhs as LESSER, EQUAL, GREATER or INDETERMINATE.
Throws:
NullPointerException - if lhs or rhs parameters are null.

equals

public boolean equals(Object obj)

Indicates whether parameter obj is "equal to" this one.

Overrides:
equals in class Object
Parameters:
obj - to compare.
Returns:
true when compare(this,(XMLGregorianCalendar)obj) == EQUAL..
See Also:
Object.hashCode(), Hashtable

hashCode

public int hashCode()

Returns a hash code consistent with the definition of the equals method.

Overrides:
hashCode in class Object
Returns:
hash code of this object.
See Also:
Object.equals(java.lang.Object), Hashtable

parse

public static XMLGregorianCalendar parse(String lexicalRepresentation)

Constructs a new XMLGregorianCalendar object by parsing its lexical string representation as defined in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation.

The string representation may not have any leading and trailing whitespaces.

The parsing is done field by field so that the following holds for any lexically correct string x:

 new XMLGregorianCalendar(x).toXMLFormat().equals(x)
 

Returns a non-null valid XMLGregorianCalendar object that holds the value indicated by the lexicalRepresentation parameter.

Parameters:
lexicalRepresentation - Lexical representation of one the 8 XML Schema calendar datatypes.
Returns:
XMLGregorianCalendar created from parsing lexicalRepresentation parameter.
Throws:
IllegalArgumentException - If the given string does not conform to the aforementioned specification.
NullPointerException - If the given string is null.

toXMLFormat

public String toXMLFormat()

Return the lexical representation of this instance. The format is specified in XML Schema 1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation".

Specific target lexical representation format is determined by getXMLSchemaType().

Returns:
XML, as String, representation of this XMLGregorianCalendar
Throws:
IllegalStateException - if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.

getXMLSchemaType

public QName getXMLSchemaType()

Return the name of the XML Schema date/time type that this instance maps to. Type is computed based on fields that are set.

Required fields for XML Schema 1.0 Date/Time Datatypes.
(timezone is optional for all date/time datatypes)
Datatype year month day hour minute second
DATETIME X X X X X X
DATE X X X
TIME X X X
GYEARMONTH X X
GMONTHDAY X X
GYEAR X
GMONTH X
GDAY X

Returns:
one of the following class constants DATETIME, TIME, DATE, GYEARMONTH, GMONTHDAY, GYEAR, GMONTH or GDAY.
Throws:
IllegalStateException - if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.

isValid

public boolean isValid()
Validate instance by getXMLSchemaType() constraints.

Returns:
true if data values are valid.

add

public void add(Duration duration)

Add duration to this instance.<\p>

The computation is specified in XML Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes>. date/time field mapping table defines the mapping from XML Schema 1.0 dateTime fields to this class' representation of those fields.

Parameters:
duration - Duration to add to this XMLGregorianCalendar.
Throws:
NullPointerException - when duration parameter is null.
IllegalStateException - when this instance is XML Schema type TIME or GMONTHDAY since duration addition is not defined for these two XML Schema builtin datatypes.

toGregorianCalendar

public GregorianCalendar toGregorianCalendar()

Convert this to java.util.GregorianCalendar.

When this instance has an undefined field, this conversion relies on the java.util.GregorianCalendar default for its corresponding field. A notable difference between XML Schema 1.0 date/time datatypes and java.util.GregorianCalendar is that Timezone value is optional for date/time datatypes and it is a required field for java.util.GregorianCalendar. See javadoc for java.util.TimeZone.getDefault() on how the default is determined. To explicitly specify the TimeZone instance, see toGregorianCalendar(TimeZone, Locale, XMLGregorianCalendar).

Field by Field Conversion from this class to java.util.GregorianCalendar
java.util.GregorianCalendar field javax.xml.datatype.XMLGregorianCalendar field
ERA getEonAndYear().signum() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD
YEAR getEonAndYear().abs().intValue()*
MONTH getMonth() - 1
DAY_OF_MONTH getDay()
AM_PM getHour() < 12 : Calendar.AM : Calendar.PM
HOUR_OF_DAY getHour()
MINUTE getMinute()
SECOND getSecond()
MILLISECOND get millisecond order from getFractionalSecond()*
GregorianCalendar.setTimeZone(TimeZone) getTimezone() formatted into Custom timezone id
* designates possible loss of precision during the conversion due to source datatype having higer precison than target datatype.

To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.

See Also:
toGregorianCalendar(java.util.TimeZone, java.util.Locale, XMLGregorianCalendar)

toGregorianCalendar

public GregorianCalendar toGregorianCalendar(TimeZone timezone,
                                             Locale aLocale,
                                             XMLGregorianCalendar defaults)

Convert this along with provided parameters to java.util.GregorianCalendar instance.

Since XML Schema 1.0 date/time datetypes has no concept of timezone ids or daylight savings timezone ids, this conversion operation allows the user to explicitly specify one with timezone parameter.

To compute the return value's TimeZone field,


fromGregorianCalendar

public static XMLGregorianCalendar fromGregorianCalendar(GregorianCalendar cal)

Convert a java.util.GregorianCalendar to XML Schema 1.0 representation.

Field by Field Conversion from java.util.GregorianCalendar to this class
javax.xml.datatype.XMLGregorianCalendar field java.util.GregorianCalendar field
setYear(int) ERA == GregorianCalendar.BC ? -YEAR : YEAR
setMonth(int) MONTH + 1
setDay(int) DAY_OF_MONTH
setTime(int,int,int, BigDecimal) HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND
setTimezone(int)* (ZONE_OFFSET + DST_OFFSET) / (60*1000)
(in minutes)

*conversion loss of information. It is not possible to represent a java.util.GregorianCalendar daylight savings timezone id in the XML Schema 1.0 date/time datatype representation.

To compute the return value's TimeZone field,


clone

public Object clone()

Creates and returns a copy of this object.

Overrides:
clone in class Object
Returns:
copy of this Object
See Also:
Cloneable

clear

public void clear()

Unset all fields to undefined.

Set all int fields to FIELD_UNDEFINED and reference fields to null.