## net.sf.saxon.value
Class DurationValue

    java.lang.Object
      |
      +--net.sf.saxon.value.Value
            |
            +--net.sf.saxon.value.AtomicValue
                  |
                  +--net.sf.saxon.value.DurationValue

All Implemented Interfaces:
  java.lang.Comparable, Expression, Item, java.io.Serializable

Direct Known Subclasses:
  MonthDurationValue, SecondsDurationValue

public class DurationValue
extends AtomicValue
implements java.lang.Comparable

A value of type xs:duration

See Also:
  Serialized Form

Field Summary
`protected int` `days`
`protected int` `hours`
`protected int` `milliseconds`
`protected int` `minutes`
`protected int` `months`
`protected boolean` `negative`
`protected int` `seconds`
`protected int` `years`

Fields inherited from interface net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD`

Constructor Summary
`protected` `DurationValue()` Private constructor for internal use
`` `DurationValue(java.lang.CharSequence s)` Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnMnDTnHnMnS

Method Summary
`DurationValue` `add(DurationValue other, XPathContext context)` Add two durations
`protected void` `badDuration(java.lang.String msg, java.lang.CharSequence s)`
`int` `compareTo(java.lang.Object other)` Compare the value to another duration value
`AtomicValue` `convert(int requiredType, XPathContext context)` Convert to target data type
`java.lang.Object` `convertToJava(java.lang.Class target, Configuration config, XPathContext context)` Convert to Java object (for passing to external functions)
`DoubleValue` `divide(DurationValue other, XPathContext context)` Divide a duration by a number
`boolean` `equals(java.lang.Object other)` Test if the two durations are of equal length.
`AtomicValue` `getComponent(int component)` Get a component of the value
`ItemType` `getItemType()` Determine the data type of the exprssion
`double` `getLengthInSeconds()` Get length of duration in seconds, assuming an average length of month.
`java.lang.String` `getStringValue()` Convert to string
`int` `hashCode()`
`DurationValue` `multiply(double factor, XPathContext context)` Multiply a duration by a number
`DurationValue` `subtract(DurationValue other, XPathContext context)` Subtract two durations

Methods inherited from class net.sf.saxon.value.AtomicValue
`convert, display, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getImplementationMethod, getPrimitiveValue, getTypedValue, iterate, process, toString`

Methods inherited from class net.sf.saxon.value.Value
`analyze, asItem, asValue, collapseWhitespace, convertJavaObjectToXPath, getDependencies, getParentExpression, getSpecialProperties, inverse, iterateSubExpressions, normalizeWhitespace, promote, simplify, stringToNumber, trimWhitespace`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### negative

    protected boolean negative

### years

    protected int years

### months

    protected int months

### days

    protected int days

### hours

    protected int hours

### minutes

    protected int minutes

### seconds

    protected int seconds

### milliseconds

    protected int milliseconds

Constructor Detail

### DurationValue

    protected DurationValue()

  Private constructor for internal use

### DurationValue

    public DurationValue(java.lang.CharSequence s)
                  throws XPathException

  Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnMnDTnHnMnS

Method Detail

### badDuration

    protected void badDuration(java.lang.String msg,
                               java.lang.CharSequence s)
                        throws XPathException

    `XPathException`

### convert

    public AtomicValue convert(int requiredType,
                               XPathContext context)
                        throws XPathException

  Convert to target data type

  Specified by:
    `convert` in class `AtomicValue`
  Parameters:
    `requiredType` - an integer identifying the required atomic type
    `context` - the evaluation context. Used primarily for error reporting, since nearly all type conversions are context-independent. The value may be null if the context is not known.
  Returns:
    an AtomicValue, a value of the required type
  Throws:
    `XPathException` - if the conversion is not possible

### getStringValue

    public java.lang.String getStringValue()

  Convert to string

  Specified by:
    `getStringValue` in interface `Item`
  Specified by:
    `getStringValue` in class `AtomicValue`
  Returns:
    ISO 8601 representation.

### getLengthInSeconds

    public double getLengthInSeconds()

  Get length of duration in seconds, assuming an average length of month. (Note, this defines a total ordering on durations which is different from the partial order defined in XML Schema; XPath 2.0 currently avoids defining an ordering at all. But the ordering here is consistent with the ordering of the two duration subtypes in XPath 2.0.)

### getItemType

    public ItemType getItemType()

  Determine the data type of the exprssion

  Specified by:
    `getItemType` in interface `Expression`
  Returns:
    Type.DURATION,

### convertToJava

    public java.lang.Object convertToJava(java.lang.Class target,
                                          Configuration config,
                                          XPathContext context)
                                   throws XPathException

  Convert to Java object (for passing to external functions)

  Overrides:
    `convertToJava` in class `AtomicValue`
  Parameters:
    `target` - The class required by the external function
    `config` - The configuration (needed for access to schema information)
  Returns:
    an object of the target class
    `XPathException`

### getComponent

    public AtomicValue getComponent(int component)
                             throws XPathException

  Get a component of the value

  Overrides:
    `getComponent` in class `AtomicValue`
    `XPathException`

### compareTo

    public int compareTo(java.lang.Object other)

  Compare the value to another duration value

  Specified by:
    `compareTo` in interface `java.lang.Comparable`
  Parameters:
    `other` - The other dateTime value
  Returns:
    negative value if this one is the shorter duration, 0 if they are equal, positive value if this one is the longer duration. For this purpose, a year is considered to be equal to 365.242199 days.
  Throws:
    `java.lang.ClassCastException` - if the other value is not a DurationValue (the parameter is declared as Object to satisfy the Comparable interface)

### equals

    public boolean equals(java.lang.Object other)

  Test if the two durations are of equal length. Note: this function is defined in XPath 2.0, but its semantics are currently unclear.

  Overrides:
    `equals` in class `java.lang.Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

### add

    public DurationValue add(DurationValue other,
                             XPathContext context)
                      throws XPathException

  Add two durations

    `XPathException`

### subtract

    public DurationValue subtract(DurationValue other,
                                  XPathContext context)
                           throws XPathException

  Subtract two durations

    `XPathException`

### multiply

    public DurationValue multiply(double factor,
                                  XPathContext context)
                           throws XPathException

  Multiply a duration by a number

    `XPathException`

### divide

    public DoubleValue divide(DurationValue other,
                              XPathContext context)
                       throws XPathException

  Divide a duration by a number

    `XPathException`