//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2018 Saxonica Limited. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// package net.sf.saxon.value; import net.sf.saxon.functions.AccessorFn; import net.sf.saxon.trans.XPathException; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; /** * Saxon implementation of the JAXP class javax.xml.datatype.XMLGregorianCalendar. * This is currently used only by the XQJ interface for XQuery: the normal representation of a * date, time, or dateTime value in Saxon is with a subclass of {@link 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.
*/ public class SaxonXMLGregorianCalendar extends XMLGregorianCalendar { /*@Nullable*/ private CalendarValue calendarValue; /*@Nullable*/ private BigInteger year; private int month = DatatypeConstants.FIELD_UNDEFINED; private int day = DatatypeConstants.FIELD_UNDEFINED; private int hour = DatatypeConstants.FIELD_UNDEFINED; private int minute = DatatypeConstants.FIELD_UNDEFINED; private int second = DatatypeConstants.FIELD_UNDEFINED; private int microsecond = DatatypeConstants.FIELD_UNDEFINED; private int tzOffset = DatatypeConstants.FIELD_UNDEFINED; /** * Create a SaxonXMLGregorianCalendar from a Saxon CalendarValue object * * @param value the CalendarValue */ public SaxonXMLGregorianCalendar(/*@NotNull*/ CalendarValue value) { clear(); setCalendarValue(value); } private SaxonXMLGregorianCalendar() { } /** * Set the calendar value of this object * * @param value the calendar value */ public void setCalendarValue(/*@NotNull*/ CalendarValue value) { calendarValue = value; try { if (value instanceof GYearValue) { year = BigInteger.valueOf(((Int64Value) value.getComponent(AccessorFn.Component.YEAR)).longValue()); } else if (value instanceof GYearMonthValue) { year = BigInteger.valueOf(((Int64Value) value.getComponent(AccessorFn.Component.YEAR)).longValue()); month = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MONTH)).longValue(); } else if (value instanceof GMonthValue) { month = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MONTH)).longValue(); } else if (value instanceof GMonthDayValue) { month = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MONTH)).longValue(); day = (int) ((Int64Value) value.getComponent(AccessorFn.Component.DAY)).longValue(); } else if (value instanceof GDayValue) { day = (int) ((Int64Value) value.getComponent(AccessorFn.Component.DAY)).longValue(); } else if (value instanceof DateValue) { year = BigInteger.valueOf(((Int64Value) value.getComponent(AccessorFn.Component.YEAR)).longValue()); month = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MONTH)).longValue(); day = (int) ((Int64Value) value.getComponent(AccessorFn.Component.DAY)).longValue(); } else if (value instanceof TimeValue) { hour = (int) ((Int64Value) value.getComponent(AccessorFn.Component.HOURS)).longValue(); minute = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MINUTES)).longValue(); second = (int) ((Int64Value) value.getComponent(AccessorFn.Component.WHOLE_SECONDS)).longValue(); microsecond = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MICROSECONDS)).longValue(); } else { year = BigInteger.valueOf(((Int64Value) value.getComponent(AccessorFn.Component.YEAR)).longValue()); month = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MONTH)).longValue(); day = (int) ((Int64Value) value.getComponent(AccessorFn.Component.DAY)).longValue(); hour = (int) ((Int64Value) value.getComponent(AccessorFn.Component.HOURS)).longValue(); minute = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MINUTES)).longValue(); second = (int) ((Int64Value) value.getComponent(AccessorFn.Component.WHOLE_SECONDS)).longValue(); microsecond = (int) ((Int64Value) value.getComponent(AccessorFn.Component.MICROSECONDS)).longValue(); } } catch (XPathException e) { throw new IllegalArgumentException(e.getMessage()); } } /** *Unset all fields to undefined.
*Set all int fields to {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} and reference fields * to null.
*/ public void clear() { year = null; month = DatatypeConstants.FIELD_UNDEFINED; day = DatatypeConstants.FIELD_UNDEFINED; hour = DatatypeConstants.FIELD_UNDEFINED; minute = DatatypeConstants.FIELD_UNDEFINED; second = DatatypeConstants.FIELD_UNDEFINED; microsecond = DatatypeConstants.FIELD_UNDEFINED; tzOffset = DatatypeConstants.FIELD_UNDEFINED; } /** *Reset this XMLGregorianCalendar to 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 {@link #clear()}
*/ public void reset() { clear(); } /** *Set low and high order component of XSD dateTime year field.
Unset this field by invoking the setter with a parameter value of null.
year parameter is
* outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setYear(BigInteger year) {
calendarValue = null;
this.year = year;
}
/**
* Set year of XSD dateTime year field.
Unset this field by invoking the setter with a parameter value of * {@link javax.xml.datatype.DatatypeConstants#FIELD_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.
null.
*/
public void setYear(int year) {
calendarValue = null;
this.year = BigInteger.valueOf(year);
}
/**
* Set month.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param month value constraints summarized in month field of date/time field mapping table. * @throws IllegalArgumentException ifmonth parameter is
* outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setMonth(int month) {
calendarValue = null;
this.month = month;
}
/**
* Set days in month.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param day value constraints summarized in day field of date/time field mapping table. * @throws IllegalArgumentException ifday parameter is
* outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setDay(int day) {
calendarValue = null;
this.day = day;
}
/**
* Set the number of minutes in the timezone offset.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param offset value constraints summarized in * timezone field of date/time field mapping table. * @throws IllegalArgumentException ifoffset parameter is
* outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setTimezone(int offset) {
calendarValue = null;
tzOffset = offset;
}
/**
* Set hours.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param hour value constraints summarized in hour field of date/time field mapping table. * @throws IllegalArgumentException ifhour parameter is outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setHour(int hour) {
calendarValue = null;
this.hour = hour;
}
/**
* Set minutes.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param minute value constraints summarized in minute field of date/time field mapping table. * @throws IllegalArgumentException ifminute parameter is outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setMinute(int minute) {
calendarValue = null;
this.minute = minute;
}
/**
* Set seconds.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param second value constraints summarized in second field of date/time field mapping table. * @throws IllegalArgumentException ifsecond parameter is outside value constraints for the field as specified in
* date/time field mapping table.
*/
public void setSecond(int second) {
calendarValue = null;
this.second = second;
}
/**
* Set milliseconds.
*Unset this field by invoking the setter with a parameter value of {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @param millisecond value constraints summarized in * millisecond field of date/time field mapping table. * @throws IllegalArgumentException ifmillisecond parameter is outside value constraints for the field as specified
* in date/time field mapping table.
*/
public void setMillisecond(int millisecond) {
calendarValue = null;
microsecond = millisecond * 1000;
}
/**
* Set fractional seconds.
*Unset this field by invoking the setter with a parameter value of null.
fractional parameter is outside value constraints for the field as specified
* in date/time field mapping table.
*/
public void setFractionalSecond(/*@NotNull*/ BigDecimal fractional) {
calendarValue = null;
second = fractional.intValue();
BigInteger micros = fractional.movePointRight(6).toBigInteger();
micros = micros.remainder(BigInteger.valueOf(1000000));
microsecond = micros.intValue();
}
/**
* Return high order component for XML Schema 1.0 dateTime datatype field for
* 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.
* * @return eon of thisXMLGregorianCalendar. The value
* returned is an integer multiple of 10^9.
* @see #getYear()
* @see #getEonAndYear()
*/
public BigInteger getEon() {
return year.divide(BigInteger.valueOf(1000000000));
}
/**
* Return low order component for XML Schema 1.0 dateTime datatype field for
* year or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
Value constraints for this value are summarized in * year field of date/time field mapping table.
* * @return year of thisXMLGregorianCalendar.
* @see #getEon()
* @see #getEonAndYear()
*/
public int getYear() {
return year.intValue();
}
/**
* 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.
* * @return sum ofeon 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 #getEon()
* @see #getYear()
*/
/*@Nullable*/
public BigInteger getEonAndYear() {
return year;
}
/**
* Return number of month or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
*Value constraints for this value are summarized in * month field of date/time field mapping table.
* * @return year of thisXMLGregorianCalendar.
*/
public int getMonth() {
return month;
}
/**
* Return day in month or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* Value constraints for this value are summarized in * day field of date/time field mapping table.
* * @see #setDay(int) */ public int getDay() { return day; } /** * Return timezone offset in minutes or * {@link javax.xml.datatype.DatatypeConstants#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 #setTimezone(int) */ public int getTimezone() { return tzOffset; } /** * Return hours or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}. * Returns {@link javax.xml.datatype.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.
* * @see #setTime(int, int, int) */ public int getHour() { return hour; } /** * Return minutes or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}. *Returns {@link javax.xml.datatype.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.
* * @see #setTime(int, int, int) */ public int getMinute() { return minute; } /** *Return seconds or {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
*Returns {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED} if this field is not defined. * When this field is not defined, the optional xs:dateTime * fractional seconds field, represented by * {@link #getFractionalSecond()} and {@link #getMillisecond()}, * must not be defined.
*Value constraints for this value are summarized in * second field of date/time field mapping table.
* * @return Second of thisXMLGregorianCalendar.
* @see #getFractionalSecond()
* @see #getMillisecond()
* @see #setTime(int, int, int)
*/
public int getSecond() {
return second;
}
/**
* Return microsecond precision of {@link #getFractionalSecond()}.
*This method represents a convenience accessor to infinite
* precision fractional second value returned by
* {@link #getFractionalSecond()}. The returned value is the rounded
* down to microseconds value of
* {@link #getFractionalSecond()}. When {@link #getFractionalSecond()}
* returns null, this method must return
* {@link DatatypeConstants#FIELD_UNDEFINED}.
Value constraints for this value are summarized in * second field of date/time field mapping table.
* * @return Millisecond of thisXMLGregorianCalendar.
* @see #getFractionalSecond()
* @see #setTime(int, int, int)
*/
public int getMicrosecond() {
BigDecimal fractionalSeconds = getFractionalSecond();
// is field undefined?
if (fractionalSeconds == null) {
return DatatypeConstants.FIELD_UNDEFINED;
}
return getFractionalSecond().movePointRight(6).intValue();
}
/**
* 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 {@link #getSecond()}, * does not return {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}.
* * @return fractional seconds of thisXMLGregorianCalendar.
* @see #getSecond()
* @see #setTime(int, int, int, java.math.BigDecimal)
*/
/*@Nullable*/
public BigDecimal getFractionalSecond() {
if (second == DatatypeConstants.FIELD_UNDEFINED) {
return null;
}
return BigDecimal.valueOf(microsecond).movePointLeft(6);
}
/**
* 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.
XMLGregorianCalendar to compare
* @return The relationship between this XMLGregorianCalendar and
* the specified xmlGregorianCalendar as
* {@link javax.xml.datatype.DatatypeConstants#LESSER},
* {@link javax.xml.datatype.DatatypeConstants#EQUAL},
* {@link javax.xml.datatype.DatatypeConstants#GREATER} or
* {@link javax.xml.datatype.DatatypeConstants#INDETERMINATE}.
* @throws NullPointerException if xmlGregorianCalendar is null.
*/
public int compare(/*@NotNull*/ XMLGregorianCalendar xmlGregorianCalendar) {
return toCalendarValue().getSchemaComparable().compareTo(
((SaxonXMLGregorianCalendar) xmlGregorianCalendar).toCalendarValue().getSchemaComparable());
}
/**
* 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).
* * @return a copy of thisXMLGregorianCalendar normalized to UTC.
*/
/*@NotNull*/
public XMLGregorianCalendar normalize() {
return new SaxonXMLGregorianCalendar(toCalendarValue().adjustTimezone(0));
}
/**
* 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 * {@link #getXMLSchemaType()}.
* * @return XML, asString, 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.
*/
public String toXMLFormat() {
return toCalendarValue().getStringValue();
}
/**
* Return the name of the XML Schema date/time type that this instance * maps to. Type is computed based on fields that are set.
* * @return One of the following class constants: * {@link javax.xml.datatype.DatatypeConstants#DATETIME}, * {@link javax.xml.datatype.DatatypeConstants#TIME}, * {@link javax.xml.datatype.DatatypeConstants#DATE}, * {@link javax.xml.datatype.DatatypeConstants#GYEARMONTH}, * {@link javax.xml.datatype.DatatypeConstants#GMONTHDAY}, * {@link javax.xml.datatype.DatatypeConstants#GYEAR}, * {@link javax.xml.datatype.DatatypeConstants#GMONTH} or * {@link javax.xml.datatype.DatatypeConstants#GDAY}. * @throws IllegalStateException if the combination of set fields * does not match one of the eight defined XML Schema builtin * date/time datatypes. */ public QName getXMLSchemaType() { if (second == DatatypeConstants.FIELD_UNDEFINED) { if (year == null) { if (month == DatatypeConstants.FIELD_UNDEFINED) { return DatatypeConstants.GDAY; } else if (day == DatatypeConstants.FIELD_UNDEFINED) { return DatatypeConstants.GMONTH; } else { return DatatypeConstants.GMONTHDAY; } } else if (day == DatatypeConstants.FIELD_UNDEFINED) { if (month == DatatypeConstants.FIELD_UNDEFINED) { return DatatypeConstants.GYEAR; } else { return DatatypeConstants.GYEARMONTH; } } return DatatypeConstants.DATE; } else if (year == null) { return DatatypeConstants.TIME; } else { return DatatypeConstants.DATETIME; } } /** * Validate instance bygetXMLSchemaType() constraints.
*
* @return true if data values are valid.
*/
public boolean isValid() {
return true;
}
/**
* Add duration to 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 dateTime fields
* to this class' representation of those fields.
XMLGregorianCalendar.
* @throws NullPointerException when duration parameter is null.
*/
public void add(/*@NotNull*/ Duration duration) {
try {
CalendarValue cv = toCalendarValue().add(((SaxonDuration) duration).getDurationValue());
setCalendarValue(cv);
} catch (XPathException err) {
throw new IllegalArgumentException(err.getMessage());
}
}
/**
* Convert this XMLGregorianCalendar to a {@link 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
* {@link #toGregorianCalendar(java.util.TimeZone, Locale, javax.xml.datatype.XMLGregorianCalendar)}.
Convert this XMLGregorianCalendar along with provided parameters
* to a {@link 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:
timeZone is non-null,
* it is the timezone field.this.getTimezone() != FIELD_UNDEFINED,
* create a java.util.TimeZone with a custom timezone id
* using the this.getTimezone().defaults.getTimezone() != FIELD_UNDEFINED,
* create a java.util.TimeZone with a custom timezone id
* using defaults.getTimezone().GregorianCalendar default timezone value
* for the host is defined as specified by
* java.util.TimeZone.getDefault().To ensure consistency in conversion implementations, the new
* GregorianCalendar should be instantiated in the following
* manner:
java.util.GregorianCalendar(TimeZone,
* Locale) with TimeZone set as specified above and the
* Locale parameter.GregorianCalendar.setGregorianChange(
* new Date(Long.MIN_VALUE)).Calendar.set(int,int)null is a legal value.
* @param aLocale provide explicit Locale. Use default GregorianCalendar locale if
* value is null.
* @param defaults provide default field values to use when corresponding
* field for this instance is FIELD_UNDEFINED or null.
* If defaultsis null or a field
* within the specified defaults is undefined,
* just use java.util.GregorianCalendar defaults.
* @return a java.util.GregorianCalendar conversion of this instance.
*/
/*@NotNull*/
public GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, /*@NotNull*/ XMLGregorianCalendar defaults) {
GregorianCalendar gc = new GregorianCalendar(timezone, aLocale);
gc.setGregorianChange(new Date(Long.MIN_VALUE));
gc.set(Calendar.ERA, year == null ? defaults.getYear() > 0 ? +1 : -1 : year.signum());
gc.set(Calendar.YEAR, year == null ? defaults.getYear() : year.abs().intValue());
gc.set(Calendar.MONTH, month == DatatypeConstants.FIELD_UNDEFINED ? defaults.getMonth() : month);
gc.set(Calendar.DAY_OF_MONTH, day == DatatypeConstants.FIELD_UNDEFINED ? defaults.getDay() : day);
gc.set(Calendar.HOUR, hour == DatatypeConstants.FIELD_UNDEFINED ? defaults.getHour() : hour);
gc.set(Calendar.MINUTE, minute == DatatypeConstants.FIELD_UNDEFINED ? defaults.getMinute() : minute);
gc.set(Calendar.SECOND, second == DatatypeConstants.FIELD_UNDEFINED ? defaults.getSecond() : second);
gc.set(Calendar.MILLISECOND, microsecond == DatatypeConstants.FIELD_UNDEFINED
? defaults.getMillisecond() : microsecond / 1000);
return gc;
}
/**
* Returns a java.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).
* * @param defaultZoneoffset default zoneoffset if this zoneoffset is * {@link javax.xml.datatype.DatatypeConstants#FIELD_UNDEFINED}. * @return TimeZone for this. */ public TimeZone getTimeZone(int defaultZoneoffset) { if (tzOffset == DatatypeConstants.FIELD_UNDEFINED) { if (defaultZoneoffset == DatatypeConstants.FIELD_UNDEFINED) { return new GregorianCalendar().getTimeZone(); } else { return new SimpleTimeZone(defaultZoneoffset * 60000, "XXX"); } } else { return new SimpleTimeZone(tzOffset * 60000, "XXX"); } } /** *Creates and returns a copy of this object.
* * @return copy of thisObject
*/
/*@NotNull*/
@SuppressWarnings({"CloneDoesntCallSuperClone"})
public Object clone() {
SaxonXMLGregorianCalendar s = new SaxonXMLGregorianCalendar();
s.setYear(year);
s.setMonth(month);
s.setDay(day);
s.setHour(hour);
s.setMinute(minute);
s.setSecond(second);
s.setMillisecond(microsecond / 1000);
s.setTimezone(tzOffset);
return s;
}
/**
* Convert this SaxonXMLGregorianCalendar to a Saxon CalendarValue object
*
* @return the corresponding CalendarValue
*/
/*@Nullable*/
public CalendarValue toCalendarValue() {
if (calendarValue != null) {
return calendarValue;
}
if (second == DatatypeConstants.FIELD_UNDEFINED) {
if (year == null) {
if (month == DatatypeConstants.FIELD_UNDEFINED) {
return new GDayValue((byte) day, tzOffset);
} else if (day == DatatypeConstants.FIELD_UNDEFINED) {
return new GMonthValue((byte) month, tzOffset);
} else {
return new GMonthDayValue((byte) month, (byte) day, tzOffset);
}
} else if (day == DatatypeConstants.FIELD_UNDEFINED) {
if (month == DatatypeConstants.FIELD_UNDEFINED) {
return new GYearValue(year.intValue(), tzOffset, true);
} else {
return new GYearMonthValue(year.intValue(), (byte) month, tzOffset, true);
}
}
return new DateValue(year.intValue(), (byte) month, (byte) day, tzOffset, true);
} else if (year == null) {
return new TimeValue((byte) hour, (byte) minute, (byte) second, getMicrosecond()*1000, tzOffset, "");
} else {
return new DateTimeValue(year.intValue(), (byte) month, (byte) day,
(byte) hour, (byte) minute, (byte) second, getMicrosecond(), tzOffset, true);
}
}
}