Duration.Add(Duration) Method

Definition

Computes a new duration whose value is this+rhs.

[Android.Runtime.Register("add", "(Ljavax/xml/datatype/Duration;)Ljavax/xml/datatype/Duration;", "GetAdd_Ljavax_xml_datatype_Duration_Handler")]
public abstract Javax.Xml.Datatype.Duration? Add (Javax.Xml.Datatype.Duration? rhs);
[<Android.Runtime.Register("add", "(Ljavax/xml/datatype/Duration;)Ljavax/xml/datatype/Duration;", "GetAdd_Ljavax_xml_datatype_Duration_Handler")>]
abstract member Add : Javax.Xml.Datatype.Duration -> Javax.Xml.Datatype.Duration

Parameters

rhs
Duration

Duration to add to this Duration

Returns

non-null valid Duration object.

Attributes

Exceptions

If the rhs parameter is null.

If two durations cannot be meaningfully added. For example, adding negative one day to one month causes this exception.

Remarks

Computes a new duration whose value is this+rhs.

For example,

"1 day" + "-3 days" = "-2 days"
            "1 year" + "1 day" = "1 year and 1 day"
            "-(1 hour,50 minutes)" + "-20 minutes" = "-(1 hours,70 minutes)"
            "15 hours" + "-3 days" = "-(2 days,9 hours)"
            "1 year" + "-1 day" = IllegalStateException

Since there's no way to meaningfully subtract 1 day from 1 month, there are cases where the operation fails in IllegalStateException.

Formally, the computation is defined as follows.

Firstly, we can assume that two Durations to be added are both positive without losing generality (i.e., (-X)+Y=Y-X, X+(-Y)=X-Y, (-X)+(-Y)=-(X+Y))

Addition of two positive Durations are simply defined as field by field addition where missing fields are treated as 0.

A field of the resulting Duration will be unset if and only if respective fields of two input Durations are unset.

Note that lhs.add(rhs) will be always successful if lhs.signum()*rhs.signum()!=-1 or both of them are normalized.

Java documentation for javax.xml.datatype.Duration.add(javax.xml.datatype.Duration).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also