Class: Duration

types~Duration(months, days, nanoseconds)

Represents a duration. A duration stores separately months, days, and seconds due to the fact that the number of days in a month varies, and a day can have 23 or 25 hours if a daylight saving is involved.

Constructor

new Duration(months, days, nanoseconds)

Creates a new instance of Duration.

Parameters:
Name Type Description
months Number

The number of months.

days Number

The number of days.

nanoseconds Number | Long | BigInt

The number of nanoseconds.

Source:

Members

(readonly) days :Number

Gets the number of days

Type:
  • Number
Source:

(readonly) months :Number

Gets the number of months

Type:
  • Number
Source:

(readonly) nanoseconds :Long

Gets the number of nanoseconds

Type:
  • Long
Source:

Methods

(package) getInternal() → {rust.DurationWrapper}

Source:
Returns:
Type
rust.DurationWrapper

toBuffer() → {Buffer}

Serializes the duration and returns the representation of the value in bytes.

Source:
Returns:
Type
Buffer

toString() → {string}

Returns the string representation of the value.

Source:
Returns:
Type
string

(static) fromBuffer(buffer) → {Duration}

Creates a new Duration instance from the binary representation of the value.

Parameters:
Name Type Description
buffer Buffer
Source:
Returns:
Type
Duration

(package, static) fromRust(arg) → {Duration}

Get duration from rust object. Not intended to be exposed in the API

Parameters:
Name Type Description
arg rust.DurationWrapper
Source:
Returns:
Type
Duration

(static) fromString(input) → {Duration}

Creates a new Duration instance from the string representation of the value.

Parameters:
Name Type Description
input String

Accepted formats:

  • multiple digits followed by a time unit like: 12h30m where the time unit can be:
    • y: years
    • mo: months
    • w: weeks
    • d: days
    • h: hours
    • m: minutes
    • s: seconds
    • ms: milliseconds
    • us or µs: microseconds
    • ns: nanoseconds
  • ISO 8601 format: P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W
  • ISO 8601 alternative format: P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]

Duration can be made negative by adding - at the beginning of the input

Source:
Returns:
Type
Duration
Examples

From formatted string

let date = fromString("4mo7d20ns");  // 1 month, 7 days, 20 nanoseconds

From ISO 8601

let date = fromString("P2DT5M");     // 2 days, 5 minutes