Share via


Duration Class

Definition

Immutable representation of a time span as defined in the W3C XML Schema 1.

[Android.Runtime.Register("javax/xml/datatype/Duration", DoNotGenerateAcw=true)]
public abstract class Duration : Java.Lang.Object
[<Android.Runtime.Register("javax/xml/datatype/Duration", DoNotGenerateAcw=true)>]
type Duration = class
    inherit Object
Inheritance
Duration
Attributes

Remarks

Immutable representation of a time span as defined in the W3C XML Schema 1.0 specification.

A Duration object represents a period of Gregorian time, which consists of six fields (years, months, days, hours, minutes, and seconds) plus a sign (+/-) field.

The first five fields have non-negative (>=0) integers or null (which represents that the field is not set), and the seconds field has a non-negative decimal or null. A negative sign indicates a negative duration.

This class provides a number of methods that make it easy to use for the duration datatype of XML Schema 1.0 with the errata.

<h2>Order relationship</h2>

Duration objects only have partial order, where two values A and B maybe either:

<ol> <li>A&lt;B (A is shorter than B) <li>A&gt;B (A is longer than B) <li>A==B (A and B are of the same duration) <li>A&lt;>B (Comparison between A and B is indeterminate) </ol>

For example, 30 days cannot be meaningfully compared to one month. The #compare(Duration duration) method implements this relationship.

See the #isLongerThan(Duration) method for details about the order relationship among Duration objects.

<h2>Operations over Duration</h2>

This class provides a set of basic arithmetic operations, such as addition, subtraction and multiplication. Because durations don't have total order, an operation could fail for some combinations of operations. For example, you cannot subtract 15 days from 1 month. See the javadoc of those methods for detailed conditions where this could happen.

Also, division of a duration by a number is not provided because the Duration class can only deal with finite precision decimal numbers. For example, one cannot represent 1 sec divided by 3.

However, you could substitute a division by 3 with multiplying by numbers such as 0.3 or 0.333.

<h2>Range of allowed values</h2>

Because some operations of Duration rely on Calendar even though Duration can hold very large or very small values, some of the methods may not work correctly on such Durations. The impacted methods document their dependency on Calendar.

Added in 1.5.

Java documentation for 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.

Constructors

Duration()
Duration(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Days

Obtains the value of the DAYS field as an integer value, or 0 if not present.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
Hours

Obtains the value of the HOURS field as an integer value, or 0 if not present.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
Minutes

Obtains the value of the MINUTES field as an integer value, or 0 if not present.

Months

Obtains the value of the MONTHS field as an integer value, or 0 if not present.

PeerReference (Inherited from Object)
Seconds

Obtains the value of the SECONDS field as an integer value, or 0 if not present.

Sign

Returns the sign of this duration in -1,0, or 1.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

XMLSchemaType

Return the name of the XML Schema date/time type that this instance maps to.

Years

Get the years value of this Duration as an int or 0 if not present.

Methods

Add(Duration)

Computes a new duration whose value is this+rhs.

AddTo(Calendar)

Adds this duration to a Calendar object.

AddTo(Date)

Adds this duration to a Date object.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Compare(Duration)

Partial order relation comparison with this Duration instance.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetField(DatatypeConstants+Field)

Gets the value of a field.

GetHashCode()

Returns a hash code consistent with the definition of the equals method.

GetTimeInMillis(Calendar)

Returns the length of the duration in milliseconds.

GetTimeInMillis(Date)

Returns the length of the duration in milliseconds.

IsLongerThan(Duration)

Checks if this duration object is strictly longer than another Duration object.

IsSet(DatatypeConstants+Field)

Checks if a field is set.

IsShorterThan(Duration)

Checks if this duration object is strictly shorter than another Duration object.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Multiply(BigDecimal)

Computes a new duration whose value is factor times longer than the value of this duration.

Multiply(Int32)

Computes a new duration whose value is factor times longer than the value of this duration.

Negate()

Returns a new Duration object whose value is -this.

NormalizeWith(Calendar)

Converts the years and months fields into the days field by using a specific time instant as the reference point.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
Subtract(Duration)

Computes a new duration whose value is this-rhs.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to