is new.
java.lang.Objectjavax.xml.datatype.XMLGregorianCalendar
Cloneable
publicabstract class XMLGregorianCalendar
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()
All maximum value space constraints listed for the fields in the table above are checked by factory methods,
The following operations are defined for this class:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Method Detail
|
|---|
clear
public abstract void
public static final intclear
FEBRUARY()
Unset all fields to undefined.
Set all int fields to
DatatypeConstants.FIELD_UNDEFINED
and reference fields to null.
public static final intMARCH
public static final intAPRIL
reset
public abstract void
public static final intreset
MAY()
Reset this XMLGregorianCalendar to its original values.
XMLGregorianCalendar is reset to the same values as when it was created with
DatatypeFactory.newXMLGregorianCalendar()
DatatypeFactory.newXMLGregorianCalendar(String lexicalRepresentation)
DatatypeFactory.newXMLGregorianCalendar( BigInteger year, int month, int day, int hour, int minute, int second, BigDecimal fractionalSecond, int timezone)
,
DatatypeFactory.newXMLGregorianCalendar( int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone)
,
DatatypeFactory.newXMLGregorianCalendar(GregorianCalendar cal)
public static final intJUNE
DatatypeFactory.newXMLGregorianCalendarDate( int year, int month, int day, int timezone)
DatatypeFactory.newXMLGregorianCalendarTime( int hours, int minutes, int seconds, int timezone)
,
DatatypeFactory.newXMLGregorianCalendarTime( int hours, int minutes, int seconds, BigDecimal fractionalSecond, int timezone)
or
DatatypeFactory.newXMLGregorianCalendarTime( int hours, int minutes, int seconds, int milliseconds, int timezone)
.
public static final intJULY
reset() is designed to allow the reuse of existing XMLGregorianCalendars thus saving resources associated with the creation of new XMLGregorianCalendars.
public static final intAUGUST
setYear
public abstract void
public static final intsetYear
SEPTEMBER(
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.
public static final intOCTOBER
Parameters:
year - value constraints summarized in
year field of date/time field mapping table
.
public static final intNOVEMBER
Throws:
IllegalArgumentException
- if year parameter is outside value constraints for the field as specified in
date/time field mapping table
.
setYear
public abstract void
public static final intsetYear
DECEMBER(int year)
Set year of XSD dateTime year field.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
public static final intFIELD_UNDEFINED
Note: if the absolute value of the year parameter is less than 10^9, the eon component of the XSD year field is set to null by this method.
public static final intLESSER
Parameters:
year - value constraints are summarized in
year field of date/time field mapping table
. If year is
DatatypeConstants.FIELD_UNDEFINED
, then eon is set to null.
setMonth
public abstract void
public static final intsetMonth
EQUAL(int month)
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
public static final intGREATER
Parameters:
month - value constraints summarized in
month field of date/time field mapping table
.
public static final intINDETERMINATE
Throws:
IllegalArgumentException
- if month parameter is outside value constraints for the field as specified in
date/time field mapping table
.
setDay
public abstract void
public static finalXMLGregorianCalendarsetDay
LEAP_YEAR_DEFAULT(int day)
Set days in month.
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.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
Parameters:
day - value constraints summarized in
day field of date/time field mapping table
.
public static finalQNameThrows:
DATETIME
IllegalArgumentException
Fully qualified name for W3C XML Schema 1.0 datatype dateTime.
- if day parameter is outside value constraints for the field as specified in
date/time field mapping table
public static finalQName.
TIME
setTimezone
public abstract void
public static finalQNamesetTimezone
DATE(int offset)
Set the number of minutes in the timezone offset.
Fully qualified name for W3C XML Schema 1.0 datatype date.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
public static finalQNameGYEARMONTH
public static finalQNameGMONTHDAY
public static finalQNameParameters:
GYEAR
offset - value constraints summarized in
timezone field of date/time field mapping table
Fully qualified name for W3C XML Schema 1.0 datatype gYear.
.
public static finalQNameThrows:
GMONTH
IllegalArgumentException
- if offset parameter is outside value constraints for the field as specified in
date/time field mapping table
.
Fully qualified name for W3C XML Schema 1.0 datatype gMonth.
setTime
public void
public static finalQNamesetTime
GDAY(int hour, int minute, int second)
public static final intMAX_TIMEZONE_OFFSET
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
.
public static final intThrows:
MIN_TIMEZONE_OFFSET
IllegalArgumentException
- if any parameter is outside value constraints for the field as specified in
date/time field mapping table
.
|
|---|
setHour
publicabstract void
setHour
XMLGregorianCalendar(int hour)
()
Set hours.
Create an instance with all date/time datatype fields set to
FIELD_UNDEFINED
or null respectively.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
|
|---|
public staticXMLGregorianCalendarcreateDateTime(BigIntegeryear, int month, int day, int hours, int minutes, int seconds,BigDecimalfractionalSecond, int timezone)
Create a Java representation of XML Schema builtin datatype dateTime. All possible fields are specified for this factory method.
hour - value constraints summarized in
hour field of date/time field mapping table
.
hour
setMinute
public abstract void
public staticXMLGregorianCalendarsetMinute
createDateTime(int minute)
(int year, int month, int day, int hour, int minute, int second)
Set minutes.
Create a Java instance of XML Schema builtin datatype dateTime.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
minute - value constraints summarized in
minute field of date/time field mapping table
.
minute
setSecond
public abstract void
public staticXMLGregorianCalendarsetSecond
createDateTime(int second)
(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds, int timezone)
Set seconds.
Create a Java representation of XML Schema builtin datatype dateTime. All possible fields are specified for this factory method.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
.
second - value constraints summarized in
second field of date/time field mapping table
.
second
setMillisecond
public abstract void
public staticXMLGregorianCalendarsetMillisecond
createDate(int millisecond)
(int year, int month, int day, int timezone)
Set milliseconds.
Create a Java representation of XML Schema builtin datatype date or g*.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED
For example, an instance of gYear can be created invoking this factory with month and day parameters set to
FIELD_UNDEFINED
.
millisecond - value constraints summarized in
millisecond field of date/time field mapping table
.
millisecond
setFractionalSecond
public abstract void
public staticXMLGregorianCalendarsetFractionalSecond
createTime(
BigDecimal
fractional)
(int hours, int minutes, int seconds, int timezone)
Unset this field by invoking the setter with a parameter value of null.
fractional - value constraints summarized in
fractional field of date/time field mapping table
.
fractional
setTime
public void
public staticXMLGregorianCalendarsetTime
createTime(int hour, int minute, int second,
BigDecimal
(int hours, int minutes, int seconds,BigDecimalfractional)
fractionalSecond, int timezone)
Set time as one unit, including the optional infinite precision fractional seconds.
Create a Java instance of XML Schema builtin datatype time.
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.
setTime
public void
public staticXMLGregorianCalendarsetTime
createTime(int hour, int minute, int second, int millisecond)
(int hours, int minutes, int seconds, int milliseconds, int timezone)
Set time as one unit, including optional milliseconds.
Create a Java instance of XML Schema builtin datatype time.
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
DatatypeConstants.FIELD_UNDEFINED
indicates this optional field is not set.
publicabstract BigInteger getEon()
Return high order component for XML Schema 1.0 dateTime datatype field for year.
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 .
The value returned is an integer multiple of 10^9.
publicabstract int getYear()
Return low order component
for
XML Schema 1.0
dateTime
dataTime
datatype field for year or
DatatypeConstants.FIELD_UNDEFINED
FIELD_UNDEFINED
.
Value constraints for this value are summarized in year field of date/time field mapping table .
publicabstract 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 .
publicabstract int getMonth()
Return number of month or
DatatypeConstants.FIELD_UNDEFINED
FIELD_UNDEFINED
.
Value constraints for this value are summarized in month field of date/time field mapping table .
publicabstract int getDay()
DatatypeConstants.FIELD_UNDEFINED
Value constraints for this value are summarized in day field of date/time field mapping table .
publicabstract int getTimezone()
DatatypeConstants.FIELD_UNDEFINED
Value constraints for this value are summarized in timezone field of date/time field mapping table .
publicabstract int getHour()
DatatypeConstants.FIELD_UNDEFINED
DatatypeConstants.FIELD_UNDEFINED
Value constraints for this value are summarized in hour field of date/time field mapping table .
publicabstract int getMinute()
DatatypeConstants.FIELD_UNDEFINED
DatatypeConstants.FIELD_UNDEFINED
Value constraints for this value are summarized in minute field of date/time field mapping table .
publicabstract int getSecond()
Return seconds or
DatatypeConstants.FIELD_UNDEFINED
FIELD_UNDEFINED
.<\p>
Returns
DatatypeConstants.FIELD_UNDEFINED
FIELD_UNDEFINED
if this field is not defined.
When this field is not defined, the optional xs:dateTime fractional seconds field, represented by
getFractionalSecond()
and
getMillisecond()
, must not be defined.
Value constraints for this value are summarized in second field of date/time field mapping table .
,
getMillisecond()
,
setTime(int, int, int)
public int getMillisecond()
Return millisecond precision of
getFractionalSecond()
Return milliseconds or
FIELD_UNDEFINED
.<\p>
This method represents a convenience accessor to infinite precision fractional second value returned by
getFractionalSecond()
Returns
FIELD_UNDEFINED
. The returned value is the rounded down to milliseconds value of
getFractionalSecond()
. When
getFractionalSecond()
returns null, this method must return
DatatypeConstants.FIELD_UNDEFINED
.
Value constraints for this value are summarized in second field of date/time field mapping table .
publicabstract 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 .
This optional field can only have a defined value when the xs:dateTime second field, represented by
getSecond()
, does not return
DatatypeConstants.FIELD_UNDEFINED
.
compare
public abstract int
public voidcompare
setYear(XMLGregorianCalendar
BigIntegerxmlGregorianCalendar)
year)
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
Set low and high order component of XSD dateTime year field.
Unset this field by invoking the setter with a parameter value of null.
public voidsetYear(int year)
Set year of XSD dateTime year field.
xsd:dateTime datatype field mapping to accessors of this class are defined in
date/time field mapping table
Unset this field by invoking the setter with a parameter value of
FIELD_UNDEFINED
.
xmlGregorianCalendar - Instance of XMLGregorianCalendar to compare
public voidsetMonth(int month)
Unset this field by invoking the setter with a parameter value of
FIELD_UNDEFINED
.
Returns:
The relationship between this XMLGregorianCalendar and the specified xmlGregorianCalendar as
DatatypeConstants.LESSER
,
DatatypeConstants.EQUAL
,
DatatypeConstants.GREATER
or
DatatypeConstants.INDETERMINATE
public voidsetDay(int day)
Unset this field by invoking the setter with a parameter value of
FIELD_UNDEFINED
.
NullPointerException
- if xmlGregorianCalendar is null.
normalize
public abstract
XMLGregorianCalendar
public voidsetTimezone(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
.
normalize
()
public voidsetTime(int hour, int minute, int second)
Normalize this instance to UTC.
Set time as one unit.
2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z
public voidsetTime(int hour, int minute, int second,BigDecimalfractional)
Set time as one unit, including the optional infinite precison fractional seconds.
Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).
public voidsetTime(int hour, int minute, int second, int millisecond)
Set time as one unit, including optional milliseconds.
public static intcompare(XMLGregorianCalendarlhs,XMLGregorianCalendarrhs)
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
.
this XMLGregorianCalendar normalized to UTC.
public boolean equals(Object obj)
Indicates whether parameter obj is "equal to" this one.
true when obj is an instance of XMLGregorianCalendar and
compare(XMLGregorianCalendar obj)
returns
DatatypeConstants.EQUAL
, otherwise false.
Throws:
NullPointerException
- If obj is null.
public int hashCode()
Returns a hash code consistent with the definition of the equals method.
public staticXMLGregorianCalendarparse(StringlexicalRepresentation)
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.
publicabstract 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() .
publicabstract 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 |
DatatypeConstants.DATETIME
|
X | X | X | X | X | X |
DatatypeConstants.DATE
|
X | X | X | |||
DatatypeConstants.TIME
|
X | X | X | |||
DatatypeConstants.GYEARMONTH
|
X | X | ||||
DatatypeConstants.GMONTHDAY
|
X | X | ||||
DatatypeConstants.GYEAR
|
X | |||||
DatatypeConstants.GMONTH
|
X | |||||
DatatypeConstants.GDAY
|
X | |||||
One of the following class constants:
DatatypeConstants.DATETIME
,
DatatypeConstants.TIME
,
DatatypeConstants.DATE
,
DatatypeConstants.GYEARMONTH
,
DatatypeConstants.GMONTHDAY
,
DatatypeConstants.GYEAR
,
DatatypeConstants.GMONTH
or
DatatypeConstants.GDAY
.
toString
public
String
toString
()
publicabstract boolean isValid()
publicabstract 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.
publicabstract GregorianCalendar toGregorianCalendar()
Convert this
XMLGregorianCalendar
to
a
GregorianCalendar
.
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() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD | ||
| YEAR | getEonAndYear() * | ||
MONTH
|
getMonth()
-
DatatypeConstants.JANUARY
+
Calendar.JANUARY
|
||
|
|
||
| DAY_OF_MONTH | getDay() | ||
HOUR_OF_DAY
|
getHour()
|
||
|
|
||
MINUTE
|
getMinute()
|
||
|
|
||
SECOND
|
getSecond()
|
||
|
|
||
MILLISECOND
|
get millisecond order from
getFractionalSecond()
*
|
||
|
|
||
GregorianCalendar.setTimeZone(TimeZone)
|
getTimezone()
|
||
|
|
||
|
|
||
higher precision
To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.
Initialize all GregorianCalendar fields by calling {(@link GegorianCalendar#clear()}.
publicabstract GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)
Convert this
XMLGregorianCalendar
along with provided parameters to
a
GregorianCalendar
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,
defined as
To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.
Initialize all GregorianCalendar fields by calling
Calendar.clear()
getTimeZone
public abstract
TimeZone
public staticXMLGregorianCalendargetTimeZone
fromGregorianCalendar(int defaultZoneoffset)
(GregorianCalendarcal)
Returns a java.util.TimeZone for this class.
Convert a java.util.GregorianCalendar to XML Schema 1.0 representation.
|
|
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
If timezone field is defined for this instance, returns TimeZone initialized with custom timezone id of zoneoffset. If timezone field is undefined, try the defaultZoneoffset that was passed in. If defaultZoneoffset is FIELD_UNDEFINED, return default timezone for this host. (Same default as java.util.GregorianCalendar).
*
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,
defaultZoneoffset - default zoneoffset if this zoneoffset is
DatatypeConstants.FIELD_UNDEFINED
.
TimeZone for this.
publicabstract Object clone()
Creates and returns a copy of this object.
public voidclear()
Unset all fields to undefined.
Set all int fields to
FIELD_UNDEFINED
and reference fields to null.
Returns:
copy of this Object
See Also:
Cloneable