Was this page helpful?
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. |
Members¶
(readonly) days :Number
Gets the number of days
Type:
- Number
(readonly) months :Number
Gets the number of months
Type:
- Number
(readonly) nanoseconds :Long
Gets the number of nanoseconds
Type:
- Long
Methods¶
toBuffer() → {Buffer}
Serializes the duration and returns the representation of the value in bytes.
Returns:
- Type
- Buffer
toString() → {string}
Returns the string representation of the value.
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 |
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 |
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:
Duration can be made negative by adding |
Returns:
- Type
- Duration
Examples
From formatted string
let date = fromString("4mo7d20ns"); // 1 month, 7 days, 20 nanosecondsFrom ISO 8601
let date = fromString("P2DT5M"); // 2 days, 5 minutes