class Duration

A representation of a duration of time within a codebase. This class provides a way to work with durations of time in a type-safe manner.

Examples

Converting seconds to milliseconds

setTimeout(() => {}, Duration.seconds(1 as Seconds).toMilliseconds());

Converting minutes to milliseconds

setTimeout(() => {}, Duration.minutes(1 as Minutes).toMilliseconds());

Example 3

Converting to milliseconds

Constructors

Static Methods

Creates a Duration from days.

Creates a Duration from hours.

Creates a Duration from milliseconds.

Creates a Duration from minutes.

Creates a Duration from seconds.

Creates a Duration from weeks.

Creates a Duration from years.

Methods

sleep(): Promise<void>

Sleeps for the current duration.

Converts the duration to days.

Converts the duration to hours.

Converts the duration to milliseconds.

Converts the duration to minutes.

Converts the duration to seconds.

Converts the duration to weeks.

Converts the duration to years.

See

  • milliseconds to quickly create a millisecond duration.