Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Duration

Represents a length of time.

The amount can be specified either as a literal value (e.g: 10) which cannot be negative, or as an unresolved number token.

When the amount is passed as a token, unit conversion is not possible.

stability

stable

Hierarchy

  • Duration

Index

Constructors

Private constructor

  • Returns Duration

Properties

Private Readonly amount

amount: any

Private components

components: any

Return the duration in a set of whole numbered time components, ordered from largest to smallest

Only components != 0 will be returned.

Can combine millis and seconds together for the benefit of toIsoString, makes the logic in there simpler.

Private Readonly unit

unit: any

Methods

formatTokenToNumber

  • formatTokenToNumber(): string
  • Returns stringified number of duration.

    stability

    stable

    Returns string

isUnresolved

  • isUnresolved(): boolean
  • Checks if duration is a token or a resolvable object.

    stability

    stable

    Returns boolean

plus

  • Add two Durations together.

    stability

    stable

    Parameters

    Returns Duration

toDays

  • toDays(opts?: TimeConversionOptions): number
  • Return the total number of days in this Duration.

    stability

    stable

    Parameters

    • Optional opts: TimeConversionOptions

    Returns number

    the value of this Duration expressed in Days.

toHours

  • toHours(opts?: TimeConversionOptions): number
  • Return the total number of hours in this Duration.

    stability

    stable

    Parameters

    • Optional opts: TimeConversionOptions

    Returns number

    the value of this Duration expressed in Hours.

toHumanString

  • toHumanString(): string
  • Turn this duration into a human-readable string.

    stability

    stable

    Returns string

toISOString

  • toISOString(): string
  • (deprecated) Return an ISO 8601 representation of this period.

    see

    https://www.iso.org/fr/standard/70907.html

    deprecated

    Use toIsoString() instead.

    Returns string

    a string starting with 'P' describing the period

toIsoString

  • toIsoString(): string
  • Return an ISO 8601 representation of this period.

    see

    https://www.iso.org/fr/standard/70907.html

    stability

    stable

    Returns string

    a string starting with 'P' describing the period

toMilliseconds

  • toMilliseconds(opts?: TimeConversionOptions): number
  • Return the total number of milliseconds in this Duration.

    stability

    stable

    Parameters

    • Optional opts: TimeConversionOptions

    Returns number

    the value of this Duration expressed in Milliseconds.

toMinutes

  • toMinutes(opts?: TimeConversionOptions): number
  • Return the total number of minutes in this Duration.

    stability

    stable

    Parameters

    • Optional opts: TimeConversionOptions

    Returns number

    the value of this Duration expressed in Minutes.

toSeconds

  • toSeconds(opts?: TimeConversionOptions): number
  • Return the total number of seconds in this Duration.

    stability

    stable

    Parameters

    • Optional opts: TimeConversionOptions

    Returns number

    the value of this Duration expressed in Seconds.

toString

  • toString(): string
  • Returns a string representation of this Duration that is also a Token that cannot be successfully resolved.

    This protects users against inadvertently stringifying a Duration object, when they should have called one of the to* methods instead.

    stability

    stable

    Returns string

unitLabel

  • unitLabel(): string
  • Returns unit of the duration.

    stability

    stable

    Returns string

Static days

  • Create a Duration representing an amount of days.

    stability

    stable

    Parameters

    • amount: number

      the amount of Days the Duration will represent.

    Returns Duration

    a new Duration representing amount Days.

Static hours

  • Create a Duration representing an amount of hours.

    stability

    stable

    Parameters

    • amount: number

      the amount of Hours the Duration will represent.

    Returns Duration

    a new Duration representing amount Hours.

Static millis

  • Create a Duration representing an amount of milliseconds.

    stability

    stable

    Parameters

    • amount: number

      the amount of Milliseconds the Duration will represent.

    Returns Duration

    a new Duration representing amount ms.

Static minutes

  • Create a Duration representing an amount of minutes.

    stability

    stable

    Parameters

    • amount: number

      the amount of Minutes the Duration will represent.

    Returns Duration

    a new Duration representing amount Minutes.

Static parse

  • Parse a period formatted according to the ISO 8601 standard.

    see

    https://www.iso.org/fr/standard/70907.html

    stability

    stable

    Parameters

    • duration: string

      an ISO-formtted duration to be parsed.

    Returns Duration

    the parsed Duration.

Static seconds

  • Create a Duration representing an amount of seconds.

    stability

    stable

    Parameters

    • amount: number

      the amount of Seconds the Duration will represent.

    Returns Duration

    a new Duration representing amount Seconds.

Generated using TypeDoc