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.fromSeconds(1).toMilliseconds());

Converting minutes to milliseconds

setTimeout(() => {}, Duration.fromMinutes(1).toMilliseconds());

Constructors

new
Duration(milliseconds: number)

Methods

toDays(): number

Converts the duration to days.

toHours(): number

Converts the duration to hours.

Converts the duration to milliseconds.

toMinutes(): number

Converts the duration to minutes.

toSeconds(): number

Converts the duration to seconds.

toWeeks(): number

Converts the duration to weeks.

toYears(): number

Converts the duration to years.

Static Methods

fromDays(days: number): Duration

Creates a Duration from days.

fromHours(hours: number): Duration

Creates a Duration from hours.

fromMilliseconds(milliseconds: number): Duration

Creates a Duration from milliseconds.

fromMinutes(minutes: number): Duration

Creates a Duration from minutes.

fromSeconds(seconds: number): Duration

Creates a Duration from seconds.

fromWeeks(weeks: number): Duration

Creates a Duration from weeks.

fromYears(years: number): Duration

Creates a Duration from years.