net.sf.saxon.value

Class GDateValue

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 byteday
protected static byte[]daysPerMonth
Test whether a candidate date is actually a valid date in the proleptic Gregorian calendar
protected bytemonth
protected static short[]monthData
protected intyear
Method Summary
intcompareTo(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.
booleanequals(Object o)
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values.
GregorianCalendargetCalendar()
ComparisonKeygetComparisonKey(XPathContext context)
Get a comparison key for this value.
AtomicValuegetComponent(int component)
Get a component of the value.
bytegetDay()
Get the day component of the date (in local form)
bytegetMonth()
Get the month component of the date (in local form)
ComparablegetSchemaComparable()
intgetYear()
Get the year component of the date (in local form)
inthashCode()
static booleanisLeapYear(int year)
Test whether a year is a leap year
static booleanisValidDate(int year, int month, int day)
Determine whether a given date is valid
protected static ConversionResultsetLexicalValue(GDateValue d, CharSequence s)
Initialize the DateValue using a character string in the format yyyy-mm-dd and an optional time zone.
DateTimeValuetoDateTime()
Convert to DateTime.

Field Detail

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 Detail

compareTo

public 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. This method implements the XPath comparison semantics.

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

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.

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

Throws: ClassCastException if the values are not comparable

getCalendar

public GregorianCalendar getCalendar()

getComparisonKey

public ComparisonKey getComparisonKey(XPathContext context)
Get a comparison key for this value. Two values are equal if and only if they their comparison keys are equal

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)

getComponent

public AtomicValue getComponent(int component)
Get a component of the value. Returns null if the timezone component is requested and is not present.

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()

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.

Returns: the starting instant of the GDateValue (with the same timezone)