Class: Duration

time.Duration(valueopt)

A duration is a time-based amount of time, such as '34.5 seconds'.

Constructor

new Duration(valueopt)

Creates a duration.

The duration is zero if no value is provided.

Parameters:
Name Type Attributes Description
value number | string | Duration <optional>

The duration in millis, an ISO 8601 string or another duration.

Members

(readonly) days :number

Gets the number of days in the duration.

Type:
  • number

(readonly) daysPart :number

Extracts the number of days in the duration.

Type:
  • number

(readonly) hours :number

Gets the number of hours in the duration.

Type:
  • number

(readonly) hoursPart :number

Extracts the number of hours in the duration.

Type:
  • number

millis :number

The total length of the duration in milliseconds.

Type:
  • number

(readonly) millisPart :number

Gets the number of milliseconds in the duration.

Type:
  • number

(readonly) minutes :number

Gets the number of minutes in the duration.

Type:
  • number

(readonly) minutesPart :number

Extracts the number of minutes in the duration.

Type:
  • number

(readonly) seconds :number

Gets the number of seconds in the duration.

Type:
  • number

(readonly) secondsPart :number

Extracts the number of seconds in the duration.

Type:
  • number

Methods

absolutized() → {Duration}

Returns a copy of this duration with a positive length.

Returns:

The absolute value of the duration.

Type
Duration

dividedBy(divisor) → {Duration}

Returns a copy of this duration divided by the specified value.

Parameters:
Name Type Description
divisor number

The value to divide the duration by.

Returns:

The new duration.

Type
Duration

isNegative() → {boolean}

Checks if the duration is negative.

Returns:
Type
boolean

isPositive() → {boolean}

Checks if the duration is positive.

Returns:
Type
boolean

isZero() → {boolean}

Checks if the duration is zero.

Returns:
Type
boolean

minus(duration) → {Duration}

Returns a copy of this duration with the specified duration subtracted.

Parameters:
Name Type Description
duration Duration | string | number

The duration to subtract or number of millis.

Returns:

The new duration.

Type
Duration

multipliedBy(multiplicand) → {Duration}

Returns a copy of this duration multiplied by the scalar.

Parameters:
Name Type Description
multiplicand number

The value to multiply the duration by.

Returns:

The new duration.

Type
Duration

negated() → {Duration}

Returns a copy of this duration with length negated.

Returns:

The negated value of the duration.

Type
Duration

plus(duration) → {Duration}

Returns a copy of this duration with the specified duration added.

Parameters:
Name Type Description
duration Duration | string | number

The duration to add or number of millis.

Returns:

The new duration.

Type
Duration

toISOString() → {string}

Returns a string representation of this duration using ISO 8601, such as PT8H6M12.345S.

Returns:

The ISO 8601 string representation of the duration.

Type
string

toJSON() → {string}

Returns a parsable string representation of this duration.

Returns:

The string representation of this duration.

Type
string

toString(options) → {string}

Returns a string representation of this duration, such as 08:06:12.

Parameters:
Name Type Description
options object

The options to create the string.

Properties
Name Type Attributes Default Description
style string <optional>
'medium'

The style of the string (short, medium, long).

Returns:

The string representation of the duration.

Type
string

valueOf() → {number}

Returns the value of the duration in milliseconds.

Returns:

The value of the duration in milliseconds.

Type
number

(static) between(startInclusive, endExclusive) → {Duration}

Obtains a Duration representing the duration between two temporal objects.

Parameters:
Name Type Description
startInclusive Date | number

The start date or millis, inclusive.

endExclusive Date | number

The end date or millis, exclusive.

Returns:

The duration between the two dates.

Type
Duration

(static) parse(isoString) → {Duration}

Creates a duration from a ISO 8601 string like [-]P[dD]T[hH][mM][s[.f]S].

Parameters:
Name Type Description
isoString string

The ISO 8601 string to parse.

Returns:

The parsed duration.

Type
Duration

(static) zero() → {Duration}

Creates a duration with zero value.

Returns:

A zero duration.

Type
Duration