Skip to main content
Module

x/duration/mod.ts>default

Make duration for deno. It is successor of dart's Duration
Latest
class default
import { default } from "https://deno.land/x/duration@1.0.1/mod.ts";

A span of time as 2^31-1 seconds.

Duration is complete successor of dart's Duration class.

Duration is not depends on Date, Timezone. Duration based on microseconds, You can convert to days, hours, minutes, seconds, milliseconds and microseconds itself.

To create a new Duration object, use single constructor giving the appropriate arguments:

Duration fastestMarathon = new Duration({hours:2, minutes:3, seconds:2});

The Duration is sum of all individual parts notice above.

assert(fastestMarathon === 123);

The parts of Duration can be a negative one.

Duration has arithmetic and compare method, You can add, subtract, multiply, divide and compare like >, <, >=, <=.

Constructors

new
default(unnamed 0: DurationOptions)

Properties

private
_duration: number
readonly
duration: number

Returns number of whole milliseconds spanned by this Duration

Same as inMilliseconds

readonly
inDays: number

Returns the number of whole days spanned by this Duration.

readonly
inHours: number

Returns the number of whole hours spanned by this Duration.

readonly
inMicroseconds: number

Returns number of whole microseconds spanned by this Duration.

readonly
inMilliseconds: number

Returns number of whole milliseconds spanned by this Duration.

readonly
inMinutes: number

Returns number of whole microseconds spanned by this Duration.

readonly
inSeconds: number

Returns the number of whole seconds spanned by this Duration.

readonly
isNegative: boolean

Returns whether this Duration is negative

readonly
isZero: boolean

Returns whether this Duration is zero

Methods

_microseconds(microseconds?): Duration

Returns new Duration with microseconds

abs(): Duration

Returns a new Duration representing the absolute value of this Duration.

add(other: Duration): Duration

Returns this Duration sum with given other Duration

compareTo(other: Duration): number

Compares this Duration to other, returning zero if the values are equal.

const duration1 = new Duration({ days: 2 });
const duration2 = new Duration({ days: 1 });

assert(duration1.compareTo(duration2) === 1)

const duration1 = new Duration({ days: 1 });
const duration2 = new Duration({ days: 2 });

assert(duration1.compareTo(duration2) === -1)

const duration1 = new Duration({ days: 1 });
const duration2 = new Duration({ days: 1 });

assert(duration1.compareTo(duration2) === 0)

divide(quotient: number): Duration

Returns this Duration divide with given quotient

lessThan(other: Duration): boolean

Returns true if this Duration is less than other Duration

lessThanEqual(other: Duration): boolean

Returns true if this Duration is less than equal with other Duration

moreThan(other: Duration): boolean

Returns true if this Duration is greater than other Duration

moreThanEqual(other: Duration): boolean

Returns true if this Duration is greater than equal with other Duration

multiply(factor: number): Duration

Returns this Duration multiply with given factor

subtract(other: Duration): Duration

Returns this Duration subtract with given other Duration

toString(): string

Static Properties

hoursPerDay: number
microsecondsPerDay
microsecondsPerHour
microsecondsPerMillisecond: number
microsecondsPerMinute
microsecondsPerSecond
millisecondsPerDay
millisecondsPerHour
millisecondsPerMinute
millisecondsPerSecond: number
minutesPerDay
minutesPerHour: number
secondsPerDay
secondsPerHour
secondsPerMinute: number
zero: Duration