Skip to content

Duration

Type

The Duration type is used to represent a time duration with a precision of 1 millisecond. See also Period for a calendar time equivalent.

Duration is instantiated through millis(), seconds(), minutes(), or hours().

Duration is normalized. This means adding 30 minutes and 40 minutes results in 1 hours and 10 minutes.

See plus() and minus() for how to add Duration to DateTime.

Methods

minus

<function> Subtracts two Durations.

Receiver

Duration

Arguments

delta - Duration - duration to subtract from this duration

Returns

Duration - difference of this and delta

Usage
seconds(5).minus(minutes(2)) == seconds(-115)

multiplyBy

<function> Multiplies Duration by a constant.

Receiver

Duration

Arguments

multiplier - Number

Returns

Duration - this multiplied with multiplier

Usage
minutes(5).multiplyBy(2) == seconds(600)

plus

<function> Adds two Durations.

Receiver

Duration

Arguments

delta - Duration - duration to add to this duration

Returns

Duration - the sum of this and delta

Usage
seconds(5).plus(minutes(2)) == seconds(125)

toSeconds

<function> Gets the total number of seconds in this Duration.

Receiver

Duration

Returns

Number - the duration in seconds

Usage
hours(1).toSeconds() == 3600

Inherited methods

toText

<function> Obtain the Text representation of this.

Receiver

T

Type Arguments

T

Returns

Text - the Text representation of this

Usage

Converts a Duration to Text. Values of 0 are left out of the toText() result.

minutes(4).plus(seconds(80)).toText() == "5minutes 20seconds"