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.

Members

Number

days

Gets the number of days.

Number

months

Gets the number of months.

Long

nanoseconds

Gets the number of nanoseconds represented as a int64.

Constructor

new

Duration

(Number months, Number days, Number or Long 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 or Long

The number of nanoseconds.

Methods

Duration.fromBuffer

(Buffer buffer)

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

Static
This function is static
Parameters:
Name Type Description
buffer Buffer
Returns:
Type Description
Duration

Duration.fromString

(String input)

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

Accepted formats:

  • multiple digits followed by a time unit like: 12h30m where the time unit can be:
    • {@code y}: years
    • {@code m}: months
    • {@code w}: weeks
    • {@code d}: days
    • {@code h}: hours
    • {@code m}: minutes
    • {@code s}: seconds
    • {@code ms}: milliseconds
    • {@code us} or {@code µs}: microseconds
    • {@code 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]
Static
This function is static
Parameters:
Name Type Description
input String
Returns:
Type Description
Duration

toBuffer

()

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

Returns:
Type Description
Buffer

toString

()

Returns the string representation of the value.

Returns:
Type Description
string