Class SaxonXMLGregorianCalendar
- All Implemented Interfaces:
Cloneable
CalendarValue
The JAXP specification for this class defines it in terms of XML Schema 1.0 semantics. This implementation is more aligned to the XPath 2.0 semantics of the data types.
Note that this class, unlike the representations of all other data types, is mutable.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a SaxonXMLGregorianCalendar from a Saxon CalendarValue object -
Method Summary
Modifier and TypeMethodDescriptionvoidAdddurationto this instance.voidclear()Unset all fields to undefined.clone()Creates and returns a copy of this object.intcompare(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.intgetDay()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.intgetHour()Return hours orDatatypeConstants.FIELD_UNDEFINED.intReturn microsecond precision ofgetFractionalSecond().intReturn minutes orDatatypeConstants.FIELD_UNDEFINED.intgetMonth()Return number of month orDatatypeConstants.FIELD_UNDEFINED.intReturn seconds orDatatypeConstants.FIELD_UNDEFINED.intReturn timezone offset in minutes orDatatypeConstants.FIELD_UNDEFINEDif this optional field is not defined.getTimeZone(int defaultZoneoffset) Returns ajava.util.TimeZonefor this class.Return the name of the XML Schema date/time type that this instance maps to.intgetYear()Return low order component for XML Schema 1.0 dateTime datatype field foryearorDatatypeConstants.FIELD_UNDEFINED.booleanisValid()Validate instance bygetXMLSchemaType()constraints.Normalize this instance to UTC.voidreset()Reset thisXMLGregorianCalendarto its original values.voidsetCalendarValue(CalendarValue value) Set the calendar value of this objectvoidsetDay(int day) Set days in month.voidsetFractionalSecond(BigDecimal fractional) Set fractional seconds.voidsetHour(int hour) Set hours.voidsetMillisecond(int millisecond) Set milliseconds.voidsetMinute(int minute) Set minutes.voidsetMonth(int month) Set month.voidsetSecond(int second) Set seconds.voidsetTimezone(int offset) Set the number of minutes in the timezone offset.voidsetYear(int year) Set year of XSDdateTimeyear field.voidsetYear(BigInteger year) Set low and high order component of XSDdateTimeyear field.Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue objectConvert thisXMLGregorianCalendarto aGregorianCalendar.toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults) Convert thisXMLGregorianCalendaralong with provided parameters to aGregorianCalendarinstance.Return the lexical representation ofthisinstance.Methods inherited from class javax.xml.datatype.XMLGregorianCalendar
equals, getMillisecond, hashCode, setTime, setTime, setTime, toString
-
Constructor Details
-
SaxonXMLGregorianCalendar
Create a SaxonXMLGregorianCalendar from a Saxon CalendarValue object- Parameters:
value- the CalendarValue
-
-
Method Details
-
setCalendarValue
Set the calendar value of this object- Parameters:
value- the calendar value
-
clear
public void clear()Unset all fields to undefined.
Set all int fields to
DatatypeConstants.FIELD_UNDEFINEDand reference fields to null.- Specified by:
clearin classXMLGregorianCalendar
-
reset
public void reset()Reset this
XMLGregorianCalendarto its original values.Saxon does not attempt to reset to the initial value as defined in the specification of the superclass, because it cannot distinguish the initial setting from subsequent changes. This method is therefore synonymous with
clear()- Specified by:
resetin classXMLGregorianCalendar
-
setYear
Set low and high order component of XSD
dateTimeyear field.Unset this field by invoking the setter with a parameter value of
null.- Specified by:
setYearin classXMLGregorianCalendar- Parameters:
year- value constraints summarized in year field of date/time field mapping table.- Throws:
IllegalArgumentException- ifyearparameter 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
dateTimeyear field.Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.Note: if the absolute value of the
yearparameter is less than 10^9, the eon component of the XSD year field is set tonullby this method.- Specified by:
setYearin classXMLGregorianCalendar- Parameters:
year- value constraints are summarized in year field of date/time field mapping table. If year isDatatypeConstants.FIELD_UNDEFINED, then eon is set tonull.
-
setMonth
public void setMonth(int month) Set month.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setMonthin classXMLGregorianCalendar- Parameters:
month- value constraints summarized in month field of date/time field mapping table.- Throws:
IllegalArgumentException- ifmonthparameter 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
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setDayin classXMLGregorianCalendar- Parameters:
day- value constraints summarized in day field of date/time field mapping table.- Throws:
IllegalArgumentException- ifdayparameter 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
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setTimezonein classXMLGregorianCalendar- Parameters:
offset- value constraints summarized in timezone field of date/time field mapping table.- Throws:
IllegalArgumentException- ifoffsetparameter is outside value constraints for the field as specified in date/time field mapping table.
-
setHour
public void setHour(int hour) Set hours.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setHourin classXMLGregorianCalendar- Parameters:
hour- value constraints summarized in hour field of date/time field mapping table.- Throws:
IllegalArgumentException- ifhourparameter is outside value constraints for the field as specified in date/time field mapping table.
-
setMinute
public void setMinute(int minute) Set minutes.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setMinutein classXMLGregorianCalendar- Parameters:
minute- value constraints summarized in minute field of date/time field mapping table.- Throws:
IllegalArgumentException- ifminuteparameter is outside value constraints for the field as specified in date/time field mapping table.
-
setSecond
public void setSecond(int second) Set seconds.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setSecondin classXMLGregorianCalendar- Parameters:
second- value constraints summarized in second field of date/time field mapping table.- Throws:
IllegalArgumentException- ifsecondparameter is outside value constraints for the field as specified in date/time field mapping table.
-
setMillisecond
public void setMillisecond(int millisecond) Set milliseconds.
Unset this field by invoking the setter with a parameter value of
DatatypeConstants.FIELD_UNDEFINED.- Specified by:
setMillisecondin classXMLGregorianCalendar- Parameters:
millisecond- value constraints summarized in millisecond field of date/time field mapping table.- Throws:
IllegalArgumentException- ifmillisecondparameter is outside value constraints for the field as specified in date/time field mapping table.
-
setFractionalSecond
Set fractional seconds.
Unset this field by invoking the setter with a parameter value of
null.- Specified by:
setFractionalSecondin classXMLGregorianCalendar- Parameters:
fractional- value constraints summarized in fractional field of date/time field mapping table.- Throws:
IllegalArgumentException- iffractionalparameter is outside value constraints for the field as specified in date/time field mapping table.
-
getEon
Return high order component for XML Schema 1.0 dateTime datatype field for
year.nullif 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:
getEonin 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 for
yearorDatatypeConstants.FIELD_UNDEFINED.Value constraints for this value are summarized in year field of date/time field mapping table.
- Specified by:
getYearin classXMLGregorianCalendar- Returns:
- year of this
XMLGregorianCalendar. - See Also:
-
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.
- Specified by:
getEonAndYearin classXMLGregorianCalendar- Returns:
- sum of
eonandBigInteger.valueOf(year)when both fields are defined. When onlyyearis defined, return it. When botheonandyearare not defined, returnnull. - See Also:
-
getMonth
public int getMonth()Return number of month or
DatatypeConstants.FIELD_UNDEFINED.Value constraints for this value are summarized in month field of date/time field mapping table.
- Specified by:
getMonthin 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:
getDayin classXMLGregorianCalendar- See Also:
-
getTimezone
public int getTimezone()Return timezone offset in minutes orDatatypeConstants.FIELD_UNDEFINEDif this optional field is not defined.Value constraints for this value are summarized in timezone field of date/time field mapping table.
- Specified by:
getTimezonein classXMLGregorianCalendar- See Also:
-
getHour
public int getHour()Return hours orDatatypeConstants.FIELD_UNDEFINED. ReturnsDatatypeConstants.FIELD_UNDEFINEDif this field is not defined.Value constraints for this value are summarized in hour field of date/time field mapping table.
- Specified by:
getHourin classXMLGregorianCalendar- See Also:
-
getMinute
public int getMinute()Return minutes orDatatypeConstants.FIELD_UNDEFINED.Returns
DatatypeConstants.FIELD_UNDEFINEDif this field is not defined.Value constraints for this value are summarized in minute field of date/time field mapping table.
- Specified by:
getMinutein classXMLGregorianCalendar- See Also:
-
getSecond
public int getSecond()Return seconds or
DatatypeConstants.FIELD_UNDEFINED.Returns
DatatypeConstants.FIELD_UNDEFINEDif this field is not defined. When this field is not defined, the optional xs:dateTime fractional seconds field, represented bygetFractionalSecond()andXMLGregorianCalendar.getMillisecond(), must not be defined.Value constraints for this value are summarized in second field of date/time field mapping table.
- Specified by:
getSecondin classXMLGregorianCalendar- Returns:
- Second of this
XMLGregorianCalendar. - See Also:
-
getMicrosecond
public int getMicrosecond()Return microsecond precision of
getFractionalSecond().This method represents a convenience accessor to infinite precision fractional second value returned by
getFractionalSecond(). The returned value is the rounded down to microseconds 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.
- Returns:
- Millisecond of this
XMLGregorianCalendar. - See Also:
-
getFractionalSecond
Return fractional seconds.
nullis 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:
getFractionalSecondin 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:dateTimedatatype field mapping to accessors of this class are defined in date/time field mapping table.- Specified by:
comparein classXMLGregorianCalendar- Parameters:
xmlGregorianCalendar- Instance ofXMLGregorianCalendarto compare- Returns:
- The relationship between
thisXMLGregorianCalendarand the specifiedxmlGregorianCalendarasDatatypeConstants.LESSER,DatatypeConstants.EQUAL,DatatypeConstants.GREATERorDatatypeConstants.INDETERMINATE. - Throws:
NullPointerException- ifxmlGregorianCalendaris null.
-
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:
normalizein classXMLGregorianCalendar- Returns:
- a copy of this
XMLGregorianCalendarnormalized to UTC.
-
toXMLFormat
Return the lexical representation of
thisinstance. 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:
toXMLFormatin 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.
- Specified by:
getXMLSchemaTypein classXMLGregorianCalendar- Returns:
- One of the following class constants:
DatatypeConstants.DATETIME,DatatypeConstants.TIME,DatatypeConstants.DATE,DatatypeConstants.GYEARMONTH,DatatypeConstants.GMONTHDAY,DatatypeConstants.GYEAR,DatatypeConstants.GMONTHorDatatypeConstants.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 bygetXMLSchemaType()constraints.- Specified by:
isValidin classXMLGregorianCalendar- Returns:
- true if data values are valid.
-
add
Add
durationto this instance.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
dateTimefields to this class' representation of those fields.- Specified by:
addin classXMLGregorianCalendar- Parameters:
duration- Duration to add to thisXMLGregorianCalendar.- Throws:
NullPointerException- whendurationparameter isnull.
-
toGregorianCalendar
Convert this
XMLGregorianCalendarto aGregorianCalendar.When
thisinstance has an undefined field, this conversion relies on thejava.util.GregorianCalendardefault for its corresponding field. A notable difference between XML Schema 1.0 date/time datatypes andjava.util.GregorianCalendaris 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 theTimeZoneinstance, seetoGregorianCalendar(java.util.TimeZone, Locale, javax.xml.datatype.XMLGregorianCalendar).- Specified by:
toGregorianCalendarin classXMLGregorianCalendar- See Also:
-
toGregorianCalendar
public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults) Convert this
XMLGregorianCalendaralong with provided parameters to aGregorianCalendarinstance.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
timezoneparameter.To compute the return value's
TimeZonefield:- when parameter
timeZoneis non-null, it is the timezone field. - else when
this.getTimezone() != FIELD_UNDEFINED, create ajava.util.TimeZonewith a custom timezone id using thethis.getTimezone(). - else when
defaults.getTimezone() != FIELD_UNDEFINED, create ajava.util.TimeZonewith a custom timezone id usingdefaults.getTimezone(). - else use the
GregorianCalendardefault timezone value for the host is defined as specified byjava.util.TimeZone.getDefault().
To ensure consistency in conversion implementations, the new
GregorianCalendarshould be instantiated in the following manner:- Create a new
java.util.GregorianCalendar(TimeZone, Locale)with TimeZone set as specified above and theLocaleparameter. - 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:
toGregorianCalendarin classXMLGregorianCalendar- Parameters:
timezone- provide Timezone.nullis 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. Ifdefaultsisnullor a field within the specifieddefaultsis undefined, just usejava.util.GregorianCalendardefaults.- Returns:
- a java.util.GregorianCalendar conversion of this instance.
- when parameter
-
getTimeZone
Returns a
java.util.TimeZonefor 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:
getTimeZonein classXMLGregorianCalendar- Parameters:
defaultZoneoffset- default zoneoffset if this zoneoffset isDatatypeConstants.FIELD_UNDEFINED.- Returns:
- TimeZone for this.
-
clone
Creates and returns a copy of this object.
- Specified by:
clonein classXMLGregorianCalendar- Returns:
- copy of this
Object
-
toCalendarValue
Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue object- Returns:
- the corresponding CalendarValue
-