Skip to main content
Module

x/durationjs/mod.ts>Duration

Get the formated time duration
Go to Latest
class Duration
import { Duration } from "https://deno.land/x/durationjs@v4.0.1/mod.ts";

A simple JavaScript class used to parse time durations

Constructors

new
Duration(timestamp?: number)

Parse milliseconds into separate units of time.

Properties

readonly
array: KeyValue[]

An array of time units and their values.

d: number
h: number
readonly
json: DurationObj

Data in the class mapped as a JavaScript Object.

m: number
ms: number
ns: number
raw: number
s: number
us: number
readonly
µs: number

Alias for microseconds.

Methods

addDays(n: number): Duration

Add more days to the duration.

addHours(n: number): Duration

Add more hours to the duration.

Add more microseconds to the duration.

Add more milliseconds to the duration.

addMinutes(n: number): Duration

Add more minutes to the duration.

Add more nanoseconds to the duration.

addSeconds(n: number): Duration

Add more seconds to the duration.

asDays(): number

Get duration as days.

asHours(): number

Get duration as hours.

asMicroseconds(): number

Get duration as microseconds.

asMilliseconds(): number

Get duration as milliseconds.

asMinutes(): number

Get duration as minutes.

asNanoseconds(): number

Get duration as nanoseconds.

asSeconds(): number

Get duration as seconds.

Clone current duration (run Duration#reload before this if you manually tweaked the properties).

Get a simple formatted duration in the form dd:hh:mm:ss:ms (Deprecated. Use Duration#toString())

Update data to match any modification to values.

setDays(n: number): Duration

Set days of the duration.

setHours(n: number): Duration

Set hours of the duration.

Set microseconds of the duration.

Set milliseconds of the duration.

setMinutes(n: number): Duration

Set minutes of the duration.

Set nanoseconds of the duration.

setSeconds(n: number): Duration

Set seconds of the duration.

toDescriptiveString(values?: string[] | null): string

Get a formatted, human-readable string of the duration.

Convert the Duration into a plain object.

toShortString(values?: string[] | null): string

Get a formatted, human-readable string of the duration.

toString(): string

Get a simple formatted duration in the form dd:hh:mm:ss:ms

toTimeString(fromT?: DurationKeys, toT?: DurationKeys): string

Get a duration formatted using colons (:).

toWordString(values?: string[] | null): string

Get a human-readable string of the duration in words.

valueOf(): number

Just the valueOf method.

Static Methods

between(duration1: string | number | Duration, duration2:
| string
| number
| undefined
| null
): Duration

Get the duration between two timestamps or two other durations.

fromString(str: string, doNotParse?): Duration

Reads a given string and parses a duration from it.

Get the duration till next midnight in milliseconds.

readString(str: string): DurationObj

Read duration data from a string.

since(when: number | Date): Duration

Get duration since a moment in time.