net.sf.saxon.value

Class GDateValue

Implemented Interfaces:
ConversionResult, GroundedValue, Item, PullEvent, Serializable, SequenceIterable, Serializable, ValueRepresentation
Known Direct Subclasses:
DateValue, GDayValue, GMonthDayValue, GMonthValue, GYearMonthValue, GYearValue

public abstract class GDateValue
extends CalendarValue

Abstract superclass for the primitive types containing date components: xs:date, xs:gYear, xs:gYearMonth, xs:gMonth, xs:gMonthDay, xs:gDay

Field Summary

protected byte
day
protected static byte[]
daysPerMonth
Test whether a candidate date is actually a valid date in the proleptic Gregorian calendar
protected byte
month
protected static short[]
monthData
protected int
year

Fields inherited from class net.sf.saxon.value.CalendarValue

NO_TIMEZONE

Fields inherited from class net.sf.saxon.value.AtomicValue

typeLabel

Fields inherited from class net.sf.saxon.value.Value

EMPTY_CLASS_ARRAY, INDETERMINATE_ORDERING

Fields inherited from interface net.sf.saxon.om.ValueRepresentation

EMPTY_VALUE_ARRAY

Method Summary

int
compareTo(CalendarValue other, XPathContext context)
Compare this value to another value of the same type, using the supplied context object to get the implicit timezone if required.
Object
convertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)
boolean
equals(Object o)
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values.
GregorianCalendar
getCalendar()
ComparisonKey
getComparisonKey(XPathContext context)
Get a comparison key for this value.
byte
getDay()
Get the day component of the date (in local form)
byte
getMonth()
Get the month component of the date (in local form)
Comparable
getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
int
getYear()
Get the year component of the date (in local form)
int
hashCode()
static boolean
isLeapYear(int year)
Test whether a year is a leap year
static boolean
isValidDate(int year, int month, int day)
Determine whether a given date is valid
protected static ConversionResult
setLexicalValue(GDateValue d, CharSequence s)
Initialize the DateValue using a character string in the format yyyy-mm-dd and an optional time zone.
DateTimeValue
toDateTime()
Convert to DateTime.

Methods inherited from class net.sf.saxon.value.CalendarValue

add, adjustTimezone, adjustTimezone, appendTimezone, appendTimezone, compareTo, getCalendar, getComparisonKey, getStringValue, getTimezoneInMinutes, getXPathComparable, hasTimezone, removeTimezone, setTimezoneInMinutes, subtract, toDateTime

Methods inherited from class net.sf.saxon.value.AtomicValue

asAtomic, checkPermittedContents, convert, convert, convertPrimitive, copyAsSubType, effectiveBooleanValue, equals, getCardinality, getComponent, getItemType, getLength, getPrimitiveType, getSchemaComparable, getStringValue, getStringValueCS, getTypeLabel, getTypedValue, getXPathComparable, isNaN, itemAt, iterate, process, setTypeLabel, subsequence, toString

Methods inherited from class net.sf.saxon.value.Value

asItem, asItem, asIterator, asValue, checkPermittedContents, convertJavaObjectToXPath, convertToJava, convertToJava, effectiveBooleanValue, equals, fromItem, getCanonicalLexicalRepresentation, getCardinality, getItemType, getIterator, getLength, getSchemaComparable, getStringValue, getStringValueCS, itemAt, iterate, iterate, makeQNameValue, process, reduce, stringToNumber, toString

Field Details

day

protected byte day

daysPerMonth

protected static byte[] daysPerMonth
Test whether a candidate date is actually a valid date in the proleptic Gregorian calendar

month

protected byte month

monthData

protected static final short[] monthData

year

protected int year

Method Details

compareTo

public int compareTo(CalendarValue other,
                     XPathContext context)
            throws NoDynamicContextException
Compare this value to another value of the same type, using the supplied context object to get the implicit timezone if required. This method implements the XPath comparison semantics.
Overrides:
compareTo in interface CalendarValue
Parameters:
other - the value to be compared
context - the XPath dynamic evaluation context (needed only to get the implicit timezone)
Returns:
-1 if this value is less, 0 if equal, +1 if greater

convertToJava

public Object convertToJava(Class target,
                            XPathContext context)
            throws XPathException
Convert to Java object (for passing to external functions)
Overrides:
convertToJava in interface Value

equals

public boolean equals(Object o)
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values. When the other operand is not an atomic value, the result is undefined (may be false, may be an exception). When the other operand is an atomic value that cannot be compared with this one, the method returns false.

The hashCode() method is consistent with equals().

This implementation performs a context-free comparison: it fails with ClassCastException if one value has a timezone and the other does not.

Overrides:
equals in interface AtomicValue
Parameters:
o - the other value
Returns:
true if the other operand is an atomic value and the two values are equal as defined by the XPath eq operator

getCalendar

public GregorianCalendar getCalendar()
Overrides:
getCalendar in interface CalendarValue

getComparisonKey

public ComparisonKey getComparisonKey(XPathContext context)
            throws NoDynamicContextException
Get a comparison key for this value. Two values are equal if and only if they their comparison keys are equal
Overrides:
getComparisonKey in interface CalendarValue
Parameters:
context - XPath dynamic evaluation context
Throws:
NoDynamicContextException - if the implicit timezone is required and is not available (because the method is being called at compile time)

getDay

public byte getDay()
Get the day component of the date (in local form)
Returns:
the day component (1-31)

getMonth

public byte getMonth()
Get the month component of the date (in local form)
Returns:
the month component (1-12)

getSchemaComparable

public Comparable getSchemaComparable()
Overrides:
getSchemaComparable in interface AtomicValue
Returns:
a Comparable that follows XML Schema comparison rules

getYear

public int getYear()
Get the year component of the date (in local form)
Returns:
the year component

hashCode

public int hashCode()

isLeapYear

public static boolean isLeapYear(int year)
Test whether a year is a leap year
Parameters:
year - the year
Returns:
true if the supplied year is a leap year

isValidDate

public static boolean isValidDate(int year,
                                  int month,
                                  int day)
Determine whether a given date is valid
Parameters:
year - the year
month - the month (1-12)
day - the day (1-31)
Returns:
true if this is a valid date

setLexicalValue

protected static ConversionResult setLexicalValue(GDateValue d,
                                                  CharSequence s)
Initialize the DateValue using a character string in the format yyyy-mm-dd and an optional time zone. Input must have format [-]yyyy-mm-dd[([+|-]hh:mm | Z)]
Parameters:
d - the "raw" DateValue to be populated
s - the supplied string value
Returns:
either the supplied GDateValue, with its data initialized; or a ValidationFailure

toDateTime

public DateTimeValue toDateTime()
Convert to DateTime.
Overrides:
toDateTime in interface CalendarValue
Returns:
the starting instant of the GDateValue (with the same timezone)