net.sf.saxon.value

Class MonthDurationValue

public final class MonthDurationValue extends DurationValue implements Comparable

A value of type xsd:yearMonthDuration
Constructor Summary
MonthDurationValue(CharSequence s)
Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnM
Method Summary
DurationValueadd(DurationValue other, XPathContext context)
Add two year-month-durations
intcompareTo(Object other)
Compare the value to another duration value
ObjectconvertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)
DecimalValuedivide(DurationValue other, XPathContext context)
Find the ratio between two durations
static MonthDurationValuefromMonths(int months)
Construct a duration value as a number of months.
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the exprssion
intgetLengthInMonths()
Get the number of months in the duration
CharSequencegetStringValueCS()
Convert to string
DurationValuemultiply(double n, XPathContext context)
Multiply duration by a number.
voidnormalize()
Normalize the value, for example 90M becomes 1H30M
DurationValuesubtract(DurationValue other, XPathContext context)
Subtract two year-month-durations

Constructor Detail

MonthDurationValue

public MonthDurationValue(CharSequence s)
Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnM

Method Detail

add

public DurationValue add(DurationValue other, XPathContext context)
Add two year-month-durations

compareTo

public int compareTo(Object other)
Compare the value to another duration value

Parameters: other The other dateTime value

Returns: negative value if this one is the earler, 0 if they are chronologically equal, positive value if this one is the later. For this purpose, dateTime values with an unknown timezone are considered to be UTC values (the Comparable interface requires a total ordering).

Throws: ClassCastException if the other value is not a DateTimeValue (the parameter is declared as Object to satisfy the Comparable interface)

convertToJava

public Object convertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)

divide

public DecimalValue divide(DurationValue other, XPathContext context)
Find the ratio between two durations

Parameters: other the dividend

Returns: the ratio, as a decimal

Throws: XPathException

fromMonths

public static MonthDurationValue fromMonths(int months)
Construct a duration value as a number of months.

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the exprssion

Parameters: th

Returns: Type.YEAR_MONTH_DURATION,

getLengthInMonths

public int getLengthInMonths()
Get the number of months in the duration

getStringValueCS

public CharSequence getStringValueCS()
Convert to string

Returns: ISO 8601 representation.

multiply

public DurationValue multiply(double n, XPathContext context)
Multiply duration by a number. Also used when dividing a duration by a number

normalize

public void normalize()
Normalize the value, for example 90M becomes 1H30M

subtract

public DurationValue subtract(DurationValue other, XPathContext context)
Subtract two year-month-durations