Class ImmutableXMLGregorianCalendar
- All Implemented Interfaces:
Cloneable
XMLGregorianCalendar
.The following methods throws IllegalStateException
:
clear()
reset()
setYear(BigInteger year)
setYear(int year)
setMonth(int month)
setDay(int day)
setTimezone(int offset)
setHour(int hour)
setMinute(int minute)
setSecond(int second)
setMillisecond(int millisecond)
setFractionalSecond(BigDecimal fractional)
add(Duration duration)
The XMLGregorianCalendar normalize()
method returned a new cloned instance that is normalized.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionConstructs the immutable XMLGregorianCalendar instance, cloning the parameter.Method Summary
Modifier and TypeMethodDescriptionvoid
void
clear()
clone()
Clones the instance.int
compare
(XMLGregorianCalendar xmlGregorianCalendar) 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.boolean
Compares this calendar to the specified object.int
getDay()
Return day in month orDatatypeConstants.FIELD_UNDEFINED
.getEon()
Return high order component for XML Schema 1.0 dateTime datatype field foryear
.Return XML Schema 1.0 dateTime datatype field foryear
.Return fractional seconds.int
getHour()
Return hours orDatatypeConstants.FIELD_UNDEFINED
.int
Return millisecond precision ofgetFractionalSecond()
.int
Return minutes orDatatypeConstants.FIELD_UNDEFINED
.int
getMonth()
Return number of month orDatatypeConstants.FIELD_UNDEFINED
.int
Return seconds orDatatypeConstants.FIELD_UNDEFINED
.int
Return timezone offset in minutes orDatatypeConstants.FIELD_UNDEFINED
if this optional field is not defined.getTimeZone
(int defaultZoneoffset) Returns ajava.util.TimeZone
for this class.Return the name of the XML Schema date/time type that this instance maps to.int
getYear()
Return low order component for XML Schema 1.0 dateTime datatype field foryear
orDatatypeConstants.FIELD_UNDEFINED
.int
hashCode()
Returns a hash code consistent with the definition of the equals method.boolean
isValid()
Validate instance bygetXMLSchemaType()
constraints.Normalize this instance to UTC.void
reset()
void
setDay
(int day) void
setFractionalSecond
(BigDecimal fractional) void
setHour
(int hour) void
setMillisecond
(int millisecond) void
setMinute
(int minute) void
setMonth
(int month) void
setSecond
(int second) void
setTimezone
(int offset) void
setYear
(int year) void
setYear
(BigInteger year) Convert thisXMLGregorianCalendar
to aGregorianCalendar
.toGregorianCalendar
(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults) Convert thisXMLGregorianCalendar
along with provided parameters to aGregorianCalendar
instance.toString()
Returns aString
representation of thisXMLGregorianCalendar
Object
.Return the lexical representation ofthis
instance.toXMLFormat
(QName datatype) Formats the string in XML for the datatype if possible.Methods inherited from class javax.xml.datatype.XMLGregorianCalendar
setTime, setTime, setTime
Constructor Details
ImmutableXMLGregorianCalendar
Constructs the immutable XMLGregorianCalendar instance, cloning the parameter.- Parameters:
xc
- The mutable XMLGregorianCalendar instance.
Method Details
clone
Clones the instance.- Specified by:
clone
in classXMLGregorianCalendar
- Returns:
- A cloned instance.
getEon
Return high order component for XML Schema 1.0 dateTime datatype field foryear
.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.
- Specified by:
getEon
in classXMLGregorianCalendar
- Returns:
- eon of this
XMLGregorianCalendar
. The value returned is an integer multiple of 10^9. - See Also:
getYear
public int getYear()Return low order component for XML Schema 1.0 dateTime datatype field foryear
orDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in year field of date/time field mapping table.
- Specified by:
getYear
in classXMLGregorianCalendar
- Returns:
- year of this
XMLGregorianCalendar
. - See Also:
getEonAndYear
Return XML Schema 1.0 dateTime datatype field foryear
.Value constraints for this value are summarized in year field of date/time field mapping table.
- Specified by:
getEonAndYear
in classXMLGregorianCalendar
- Returns:
- sum of
eon
andBigInteger.valueOf(year)
when both fields are defined. When onlyyear
is defined, return it. When botheon
andyear
are not defined, returnnull
. - See Also:
getMonth
public int getMonth()Return number of month orDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in month field of date/time field mapping table.
- Specified by:
getMonth
in classXMLGregorianCalendar
- Returns:
- year of this
XMLGregorianCalendar
.
getDay
public int getDay()Return day in month orDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in day field of date/time field mapping table.
- Specified by:
getDay
in classXMLGregorianCalendar
getTimezone
public int getTimezone()Return timezone offset in minutes orDatatypeConstants.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.
- Specified by:
getTimezone
in classXMLGregorianCalendar
getHour
public int getHour()Return hours orDatatypeConstants.FIELD_UNDEFINED
.Returns
DatatypeConstants.FIELD_UNDEFINED
if this field is not defined.Value constraints for this value are summarized in hour field of date/time field mapping table.
- Specified by:
getHour
in classXMLGregorianCalendar
getMinute
public int getMinute()Return minutes orDatatypeConstants.FIELD_UNDEFINED
.Returns
DatatypeConstants.FIELD_UNDEFINED
if this field is not defined.Value constraints for this value are summarized in minute field of date/time field mapping table.
- Specified by:
getMinute
in classXMLGregorianCalendar
getSecond
public int getSecond()Return seconds orDatatypeConstants.FIELD_UNDEFINED
.Returns
DatatypeConstants.FIELD_UNDEFINED
if this field is not defined. When this field is not defined, the optional xs:dateTime fractional seconds field, represented bygetFractionalSecond()
andgetMillisecond()
, must not be defined.Value constraints for this value are summarized in second field of date/time field mapping table.
- Specified by:
getSecond
in classXMLGregorianCalendar
- Returns:
- Second of this
XMLGregorianCalendar
. - See Also:
getMillisecond
public int getMillisecond()Return millisecond precision ofgetFractionalSecond()
.This method represents a convenience accessor to infinite precision fractional second value returned by
getFractionalSecond()
. The returned value is the rounded down to milliseconds value ofgetFractionalSecond()
. WhengetFractionalSecond()
returnsnull
, this method must returnDatatypeConstants.FIELD_UNDEFINED
.Value constraints for this value are summarized in second field of date/time field mapping table.
- Overrides:
getMillisecond
in classXMLGregorianCalendar
- Returns:
- Millisecond of this
XMLGregorianCalendar
. - See Also:
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 returnDatatypeConstants.FIELD_UNDEFINED
.- Specified by:
getFractionalSecond
in classXMLGregorianCalendar
- Returns:
- fractional seconds of this
XMLGregorianCalendar
. - See Also:
compare
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.- Specified by:
compare
in classXMLGregorianCalendar
- Parameters:
xmlGregorianCalendar
- Instance ofXMLGregorianCalendar
to compare- Returns:
- The relationship between
this
XMLGregorianCalendar
and the specifiedxmlGregorianCalendar
asDatatypeConstants.LESSER
,DatatypeConstants.EQUAL
,DatatypeConstants.GREATER
orDatatypeConstants.INDETERMINATE
. - Throws:
NullPointerException
- ifxmlGregorianCalendar
is null.
equals
Compares this calendar to the specified object. The result istrue
if and only if the argument is not null and is anXMLGregorianCalendar
object that represents the same instant in time as this object.- Overrides:
equals
in classXMLGregorianCalendar
- Parameters:
obj
- to compare.- Returns:
true
whenobj
is an instance ofXMLGregorianCalendar
andcompare(XMLGregorianCalendar obj)
returnsDatatypeConstants.EQUAL
, otherwisefalse
.
hashCode
public int hashCode()Returns a hash code consistent with the definition of the equals method.- Overrides:
hashCode
in classXMLGregorianCalendar
- Returns:
- hash code of this object.
toXMLFormat
Return the lexical representation ofthis
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()
.- Specified by:
toXMLFormat
in classXMLGregorianCalendar
- Returns:
- XML, as
String
, representation of thisXMLGregorianCalendar
- Throws:
IllegalStateException
- if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
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 - Specified by:
getXMLSchemaType
in classXMLGregorianCalendar
- Returns:
- One of the following class constants:
DatatypeConstants.DATETIME
,DatatypeConstants.TIME
,DatatypeConstants.DATE
,DatatypeConstants.GYEARMONTH
,DatatypeConstants.GMONTHDAY
,DatatypeConstants.GYEAR
,DatatypeConstants.GMONTH
orDatatypeConstants.GDAY
. - Throws:
IllegalStateException
- if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.
toString
Returns aString
representation of thisXMLGregorianCalendar
Object
.The result is a lexical representation generated by
toXMLFormat()
.- Overrides:
toString
in classXMLGregorianCalendar
- Returns:
- A non-
null
validString
representation of thisXMLGregorianCalendar
. - Throws:
IllegalStateException
- if the combination of set fields does not match one of the eight defined XML Schema builtin date/time datatypes.- See Also:
isValid
public boolean isValid()Validate instance bygetXMLSchemaType()
constraints.- Specified by:
isValid
in classXMLGregorianCalendar
- Returns:
- true if data values are valid.
toGregorianCalendar
Convert thisXMLGregorianCalendar
to aGregorianCalendar
.When
this
instance has an undefined field, this conversion relies on thejava.util.GregorianCalendar
default for its corresponding field. A notable difference between XML Schema 1.0 date/time datatypes andjava.util.GregorianCalendar
is that Timezone value is optional for date/time datatypes and it is a required field forjava.util.GregorianCalendar
. See javadoc forjava.util.TimeZone.getDefault()
on how the default is determined. To explicitly specify theTimeZone
instance, seetoGregorianCalendar(TimeZone, Locale, XMLGregorianCalendar)
.
* designates possible loss of precision during the conversion due to source datatype having higher precision than target datatype.Field by Field Conversion from this class to java.util.GregorianCalendar
java.util.GregorianCalendar
fieldjavax.xml.datatype.XMLGregorianCalendar
fieldERA
getEonAndYear()
.signum() < 0 ? GregorianCalendar.BC : GregorianCalendar.AD
YEAR
getEonAndYear()
.abs().intValue()
*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()
formatted into Custom timezone idTo ensure consistency in conversion implementations, the new
GregorianCalendar
should be instantiated in following manner.- Using
timeZone
value as defined above, create a newjava.util.GregorianCalendar(timeZone,Locale.getDefault())
. - Initialize all GregorianCalendar fields by calling
Calendar.clear()
. - Obtain a pure Gregorian Calendar by invoking
GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE))
. - Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND are set using the method
Calendar.set(int,int)
- Specified by:
toGregorianCalendar
in classXMLGregorianCalendar
- See Also:
- Using
toGregorianCalendar
public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults) Convert thisXMLGregorianCalendar
along with provided parameters to aGregorianCalendar
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,- when parameter
timeZone
is non-null, it is the timezone field. - else when
this.getTimezone() != FIELD_UNDEFINED
, create ajava.util.TimeZone
with a custom timezone id using thethis.getTimezone()
. - else when
defaults.getTimezone() != FIELD_UNDEFINED
, create ajava.util.TimeZone
with a custom timezone id usingdefaults.getTimezone()
. - else use the
GregorianCalendar
default timezone value for the host is defined as specified byjava.util.TimeZone.getDefault()
.
To ensure consistency in conversion implementations, the new
GregorianCalendar
should be instantiated in following manner.- Create a new
java.util.GregorianCalendar(TimeZone, Locale)
with TimeZone set as specified above and theLocale
parameter. - Initialize all GregorianCalendar fields by calling
Calendar.clear()
- Obtain a pure Gregorian Calendar by invoking
GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE))
. - Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND are set using the method
Calendar.set(int,int)
- Specified by:
toGregorianCalendar
in classXMLGregorianCalendar
- Parameters:
timezone
- provide Timezone.null
is a legal value.aLocale
- provide explicit Locale. Use default GregorianCalendar locale if value isnull
.defaults
- provide default field values to use when corresponding field for this instance is FIELD_UNDEFINED or null. Ifdefaults
isnull
or a field within the specifieddefaults
is undefined, just usejava.util.GregorianCalendar
defaults.- Returns:
- a java.util.GregorianCalendar conversion of this instance.
- when parameter
getTimeZone
Returns ajava.util.TimeZone
for this class.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).
- Specified by:
getTimeZone
in classXMLGregorianCalendar
- Parameters:
defaultZoneoffset
- default zoneoffset if this zoneoffset isDatatypeConstants.FIELD_UNDEFINED
.- Returns:
- TimeZone for this.
toXMLFormat
Formats the string in XML for the datatype if possible.- Parameters:
datatype
- The XML date/time datatype.- Throws:
IllegalArgumentException
- If the datatypeIllegalStateException
- If the combination of set fields does not match one of the eight defined XML Schema built-in date/time datatypes.
clear
public void clear()- Specified by:
clear
in classXMLGregorianCalendar
reset
public void reset()- Specified by:
reset
in classXMLGregorianCalendar
setYear
- Specified by:
setYear
in classXMLGregorianCalendar
setYear
public void setYear(int year) - Specified by:
setYear
in classXMLGregorianCalendar
setMonth
public void setMonth(int month) - Specified by:
setMonth
in classXMLGregorianCalendar
setDay
public void setDay(int day) - Specified by:
setDay
in classXMLGregorianCalendar
setTimezone
public void setTimezone(int offset) - Specified by:
setTimezone
in classXMLGregorianCalendar
setHour
public void setHour(int hour) - Specified by:
setHour
in classXMLGregorianCalendar
setMinute
public void setMinute(int minute) - Specified by:
setMinute
in classXMLGregorianCalendar
setSecond
public void setSecond(int second) - Specified by:
setSecond
in classXMLGregorianCalendar
setMillisecond
public void setMillisecond(int millisecond) - Specified by:
setMillisecond
in classXMLGregorianCalendar
setFractionalSecond
- Specified by:
setFractionalSecond
in classXMLGregorianCalendar
add
- Specified by:
add
in classXMLGregorianCalendar
normalize
Normalize this instance to UTC.
2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z
Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).
- Specified by:
normalize
in classXMLGregorianCalendar
- Returns:
- A
clone()
'd instance ofXMLGregorianCalendar
normalized to UTC.