Options
All
  • Public
  • Public/Protected
  • All
Menu

A simple representation for time durations, based on TimeUnit.

Hierarchy

  • Duration

Implements

Index

Constructors

constructor

Properties

duration

duration: number

unit

unit: TimeUnit

Methods

convertTo

  • Returns a new Duration value that represents this converted to use the given unit.

    Note that this may be a lossy conversion, e.g. when converting 27 hours to 1 day, there's a loss of fidelity.

    Parameters

    Returns Duration

equals

hashCode

  • hashCode(): number

isFinite

  • isFinite(): boolean
  • This method returns true if this duration is finite, or `false otherwise.

    Returns boolean

minus

  • Subtracts the other duration from this.

    Note that the unit used for the result will be the more finer grained one out of the two:

    // Result will be 21 hours
    Duration.days(1).minus(Duration.hours(3))
    

    Parameters

    Returns Duration

negate

plus

  • Return the sum of this duration and other.

    Note that the unit used for the result will be the more finer grained one out of the two.

    // Result will be 27 hours
    Duration.days(1).plus(Duration.hours(3))
    

    Parameters

    Returns Duration

toDays

  • toDays(): number

toHours

  • toHours(): number

toMicros

  • toMicros(): number
  • Calculates the microseconds described by the source Duration.

    Returns number

toMillis

  • toMillis(): number
  • Calculates the milliseconds described by the source Duration.

    Returns number

toMinutes

  • toMinutes(): number
  • Calculates the minutes described by the source Duration.

    Returns number

toNanos

  • toNanos(): number
  • Calculates the nanoseconds described by the source Duration.

    Returns number

toSeconds

  • toSeconds(): number
  • Calculates the seconds described by the source Duration.

    Returns number

toString

  • toString(): string

Static days

  • Constructs a Duration instance out of a value representing days.

    Parameters

    • d: number

    Returns Duration

Static hours

  • Constructs a Duration instance out of a value representing hours.

    Parameters

    • d: number

    Returns Duration

Static inf

Static micros

  • Constructs a Duration instance out of a value representing microseconds.

    Parameters

    • d: number

    Returns Duration

Static millis

  • Constructs a Duration instance out of a value representing milliseconds.

    Parameters

    • d: number

    Returns Duration

Static minutes

  • Constructs a Duration instance out of a value representing minutes.

    Parameters

    • d: number

    Returns Duration

Static nanos

  • Constructs a Duration instance out of a value representing nanoseconds.

    Parameters

    • d: number

    Returns Duration

Static negInf

Static of

  • Wraps the argument in a Duration.millis reference, in case it's a number, otherwise returns the argument as is.

    In Javascript code it is customary to express durations with numbers representing milliseconds and in functions it's good to still allow developers to do that because it's the standard convention.

    Thus one can work with a union type like number | Duration. And in case a number is given, then it is interpreted as milliseconds.

    Usage:

    function delay(d: number | Duration, r: () => {}) {
      const millis = Duration.of(d).toMillis()
      return setTimeout(r, millis)
    }
    

    Parameters

    Returns Duration

Static seconds

  • Constructs a Duration instance out of a value representing seconds.

    Parameters

    • d: number

    Returns Duration

Static zero

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc