Package net.sf.saxon.value
Class GDateValue
java.lang.Object
net.sf.saxon.value.AtomicValue
net.sf.saxon.value.CalendarValue
net.sf.saxon.value.GDateValue
- All Implemented Interfaces:
Iterable<AtomicValue>
,AtomicMatchKey
,AtomicSequence
,GroundedValue
,IdentityComparable
,Item
,Sequence
,ConversionResult
- Direct Known Subclasses:
DateValue
,GDayValue
,GMonthDayValue
,GMonthValue
,GYearMonthValue
,GYearValue
Abstract superclass for the primitive types containing date components: xs:date, xs:gYear,
xs:gYearMonth, xs:gMonth, xs:gMonthDay, xs:gDay
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
protected static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte
protected static byte[]
Test whether a candidate date is actually a valid date in the proleptic Gregorian calendarprotected final boolean
protected final byte
protected static final short[]
protected final int
Fields inherited from class net.sf.saxon.value.CalendarValue
MISSING_TIMEZONE, NO_TIMEZONE
Fields inherited from class net.sf.saxon.value.AtomicValue
typeLabel
-
Constructor Summary
ConstructorsModifierConstructorDescriptionGDateValue
(int year, byte month, byte day, boolean hasNoYearZero, int tzMinutes, AtomicType typeLabel) protected
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check that the value can be handled in SaxonJSint
compareTo
(CalendarValue other, int implicitTimezone) Compare this value to another value of the same type, using the supplied context object to get the implicit timezone if required.boolean
The equals() methods on atomic values is defined to follow the semantics of eq when applied to two atomic values.Get a Java Calendar object that represents this date/time value.getComponent
(AccessorFn.Component component) Get a component of the 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)getXPathComparable
(StringCollator collator, int implicitTimezone) Get an object value that implements the XPath equality and ordering comparison semantics for this value.int
getYear()
Get the year component of the date (in local form)int
hashCode()
Returns a hash code value for the object.static boolean
isLeapYear
(int year) Test whether a year is a leap yearstatic boolean
isValidDate
(int year, int month, int day) Determine whether a given date is validprotected GDateValue.MutableGDateValue
protected static void
setLexicalValue
(GDateValue.MutableGDateValue m, UnicodeString s, boolean allowYearZero) Initialize the DateValue using a character string in the format yyyy-mm-dd and an optional time zone.Convert to DateTime.Methods inherited from class net.sf.saxon.value.CalendarValue
add, adjustTimezone, adjustTimezone, appendString, appendTimezone, appendTimezone, appendTwoDigits, asMapKey, getTimezoneInMinutes, getXMLGregorianCalendar, getXPathMatchKey, hasTimezone, identityHashCode, isIdentical, makeCalendarValue, removeTimezone, subtract
Methods inherited from class net.sf.saxon.value.AtomicValue
asAtomic, atomize, checkPermittedContents, copyAsSubType, effectiveBooleanValue, getCanonicalLexicalRepresentation, getCardinality, getGenre, getItemType, getLength, getPrimitiveStringValue, getPrimitiveType, getUnicodeStringValue, getUType, head, isIdentical, isNaN, isUntypedAtomic, itemAt, iterate, iterator, show, toShortString, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.sf.saxon.expr.sort.AtomicMatchKey
asAtomic
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
Methods inherited from interface net.sf.saxon.om.Item
getStringValue, isStreamed, reduce, subsequence
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Field Details
-
year
protected final int year -
month
protected final byte month -
day
protected final byte day -
hasNoYearZero
protected final boolean hasNoYearZero -
daysPerMonth
protected static byte[] daysPerMonthTest whether a candidate date is actually a valid date in the proleptic Gregorian calendar -
monthData
protected static final short[] monthData
-
-
Constructor Details
-
GDateValue
public GDateValue(int year, byte month, byte day, boolean hasNoYearZero, int tzMinutes, AtomicType typeLabel) -
GDateValue
-
-
Method Details
-
makeMutableCopy
-
getYear
public int getYear()Get the year component of the date (in local form)- Returns:
- the year component, as represented internally (allowing a year zero)
-
getMonth
public byte getMonth()Get the month component of the date (in local form)- Returns:
- the month component (1-12)
-
getDay
public byte getDay()Get the day component of the date (in local form)- Returns:
- the day component (1-31)
-
getCalendar
Description copied from class:CalendarValue
Get a Java Calendar object that represents this date/time value. The Calendar object will be newly created for the purpose. This will respect the timezone if there is one (provided the timezone is within the range supported by theGregorianCalendar
class, which in practice means that it is not -14:00). If there is no timezone or if the timezone is out of range, the result will be in GMT.- Specified by:
getCalendar
in classCalendarValue
- Returns:
- A Calendar object representing the date and time. Note that Java can only represent the time to millisecond precision.
-
setLexicalValue
protected static void setLexicalValue(GDateValue.MutableGDateValue m, UnicodeString s, boolean allowYearZero) 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:
m
- the "raw" MutableGDateValue to be populated: this is modified in-situ. If the string is invalid, the error field of the MutableGDateValue will be set.s
- the supplied string valueallowYearZero
- true if (as in XSD 1.1) there is a year zero, false if (as in XSD 1.0) there is not
-
isValidDate
public static boolean isValidDate(int year, int month, int day) Determine whether a given date is valid- Parameters:
year
- the year (permitting year zero)month
- the month (1-12)day
- the day (1-31)- Returns:
- true if this is a valid date
-
isLeapYear
public static boolean isLeapYear(int year) Test whether a year is a leap year- Parameters:
year
- the year (permitting year zero)- Returns:
- true if the supplied year is a leap year
-
checkValidInJavascript
Check that the value can be handled in SaxonJS- Overrides:
checkValidInJavascript
in classAtomicValue
- Throws:
XPathException
- if it can't be handled in SaxonJS
-
equals
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 classAtomicValue
- 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
-
hashCode
public int hashCode()Description copied from class:AtomicValue
Returns a hash code value for the object.- Overrides:
hashCode
in classAtomicValue
-
compareTo
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.- Specified by:
compareTo
in classCalendarValue
- Parameters:
other
- the value to be comparedimplicitTimezone
- the implicit timezone to be used for a value with no timezone- Returns:
- -1 if this value is less, 0 if equal, +1 if greater
- Throws:
NoDynamicContextException
- if the result depends on the implicit timezone and the supplied timezone isCalendarValue.MISSING_TIMEZONE
-
toDateTime
Convert to DateTime.- Specified by:
toDateTime
in classCalendarValue
- Returns:
- the starting instant of the GDateValue (with the same timezone)
-
getSchemaComparable
-
getXPathComparable
public XPathComparable getXPathComparable(StringCollator collator, int implicitTimezone) throws NoDynamicContextException Description copied from class:AtomicValue
Get an object value that implements the XPath equality and ordering comparison semantics for this value. A collation is supplied for comparing strings, and an implicit timezone for comparing date/time values that have no saved timezone. An atomic value may return itself as the result, provided that its ordering rules are independent of the collation and timezone, and provided that it implements the XPathComparable interface: which means that its compareTo, equals, and hashCode methods must be compatible with the rules for XPath value comparisons.- Overrides:
getXPathComparable
in classCalendarValue
- Parameters:
collator
- the collation to be used when comparing stringsimplicitTimezone
- the implicit timezone in the dynamic context, used when comparing dates/times with and without timezone- Returns:
- an Object that implements the XPath value comparison semantics with respect to this atomic value. For an atomic type that is not ordered (according to XPath rules), return null.
- Throws:
NoDynamicContextException
- if the supplied implicit timezone is "NO_TIMEZONE" (meaning unknown), and the implicit timezone is actually required because the value in question is a date/time value with no timezone. This can cause a failure to evaluate expressions statically (because the implicit timezone is not known statically), and it will then be caught, meaning that the expression has to be evaluated dynamically.
-
getComponent
Get a component of the value. Returns null if the timezone component is requested and is not present.- Overrides:
getComponent
in classAtomicValue
- Parameters:
component
- the required component- Returns:
- the value of the requested component of this value
- Throws:
XPathException
- if a dynamic error occurs
-