Duration class with an interface similar to the tc39 Temporal proposal. Since it's not fully finalized, and polyfills have inconsistent compatibility, for now this shim class will be used to set durations in Pub/Sub.
This class will remain here for at least the next major version, eventually to be replaced by the tc39 Temporal.Duration built-in.
https://tc39.es/proposal-temporal/docs/duration.html https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration
Package
@google-cloud/pubsubProperties
hours
get hours(): number;Equivalent to total('hour').
milliseconds
get milliseconds(): number;Equivalent to total('millisecond').
minutes
get minutes(): number;Equivalent to total('minute').
seconds
get seconds(): number;Equivalent to total('second').
Methods
add(other)
add(other: DurationLike | Duration): Duration;Adds another Duration to this one and returns a new Duration.
| Parameter | |
|---|---|
| Name | Description |
other |
DurationLike | Duration
A Duration or Duration-like object, like from() takes. |
| Returns | |
|---|---|
| Type | Description |
Duration |
A new Duration. |
compare(first, second)
static compare(first: Duration, second: Duration): 0 | 1 | -1;Compare two Duration objects. Returns -1 if the first is less than the second, zero if they are equal, 1 if the first is greater than the second.
Unlike tc39, this version does not accept options for relativeTo.
| Parameters | |
|---|---|
| Name | Description |
first |
Duration
|
second |
Duration
|
| Returns | |
|---|---|
| Type | Description |
0 | 1 | -1 |
|
from(durationLike)
static from(durationLike: DurationLike | Duration): Duration;Creates a Duration from a DurationLike, which is an object containing zero or more of the following: hours, seconds, minutes, millis.
| Parameter | |
|---|---|
| Name | Description |
durationLike |
DurationLike | Duration
|
| Returns | |
|---|---|
| Type | Description |
Duration |
|
subtract(other)
subtract(other: DurationLike | Duration): Duration;Subtracts another Duration from this one and returns a new Duration.
| Parameter | |
|---|---|
| Name | Description |
other |
DurationLike | Duration
A Duration or Duration-like object, like from() takes. |
| Returns | |
|---|---|
| Type | Description |
Duration |
A new Duration. |
total(totalOf)
total(totalOf: TotalOfUnit): number;Calculates the total number of units of type 'totalOf' that would fit inside this duration. The tc39 options parameter is not supported.
| Parameter | |
|---|---|
| Name | Description |
totalOf |
TotalOfUnit
|
| Returns | |
|---|---|
| Type | Description |
number |
|
totalOf(totalOf)
totalOf(totalOf: TotalOfUnit): number;Calculates the total number of units of type 'totalOf' that would fit inside this duration.
No longer part of the tc39 spec, superseded by total().
| Parameter | |
|---|---|
| Name | Description |
totalOf |
TotalOfUnit
|
| Returns | |
|---|---|
| Type | Description |
number |
|