Internal
Should not be called by user directly.
Optional
base: DataAPIDurationPrivate
_daysPrivate
_indexPrivate
_monthsPrivate
_nanosecondsPrivate
_negativePrivate
Readonly
validatePrivate
_validatePrivate
_validatePrivate
_validatePrivate
_validateAdds the given number of days to this DataAPIDurationBuilder
.
If the total number of days exceeds 2147483647
(2^31 - 1), a RangeError
is thrown.
The days may be negative to perform a subtraction operation, but if the total number of days becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of days to add
The mutated builder instance
// '14d'
const span = duration.builder()
.addDays(14)
.build();
// true
duration('2w').equals(span)
Adds the given number of hours to this DataAPIDurationBuilder
.
Hours are converted to nanoseconds before being added (1 hour = 3,600,000,000,000 nanoseconds).
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The hours may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of hours to add
The mutated builder instance
// '10h'
const span = duration.builder()
.addHours(10)
.build();
// true
duration('600m').equals(span)
Adds the given number of microseconds to this DataAPIDurationBuilder
.
Microseconds are converted to nanoseconds before being added (1 microsecond = 1,000 nanoseconds).
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The microseconds may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of microseconds to add
The mutated builder instance
// '1000us'
const span = duration.builder()
.addMicros(1000)
.build();
// true
duration('1ms').equals(span)
Adds the given number of milliseconds to this DataAPIDurationBuilder
.
Milliseconds are converted to nanoseconds before being added (1 millisecond = 1,000,000 nanoseconds).
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The milliseconds may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of milliseconds to add
The mutated builder instance
// '1000ms'
const span = duration.builder()
.addMillis(1000)
.build();
// true
duration('1s').equals(span)
Adds the given number of minutes to this DataAPIDurationBuilder
.
Minutes are converted to nanoseconds before being added (1 minute = 60,000,000,000 nanoseconds).
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The minutes may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of minutes to add
The mutated builder instance
// '10m'
const span = duration.builder()
.addMinutes(10)
.build();
// true
duration('600s').equals(span)
Adds the given number of months to this DataAPIDurationBuilder
.
If the total number of months exceeds 2147483647
(2^31 - 1), a RangeError
is thrown.
The months may be negative to perform a subtraction operation, but if the total number of months becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of months to add
The mutated builder instance
// '24mo'
const span = duration.builder()
.addMonths(24)
.build();
// true
duration('2y').equals(span)
Adds the given number of nanoseconds to this DataAPIDurationBuilder
.
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The nanoseconds may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of nanoseconds to add
The mutated builder instance
// '1000ns'
const span = duration.builder()
.addNanos(1000)
.build();
// true
duration('1us').equals(span)
Adds the given number of seconds to this DataAPIDurationBuilder
.
Seconds are converted to nanoseconds before being added (1 second = 1,000,000,000 nanoseconds).
If the total number of nanoseconds exceeds 9223372036854775807n
(2^63 - 1), a RangeError
is thrown.
The seconds may be negative to perform a subtraction operation, but if the total number of nanoseconds becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of seconds to add
The mutated builder instance
// '10s'
const span = duration.builder()
.addSeconds(10)
.build();
// true
duration('10000ms').equals(span)
Adds the given number of weeks to this DataAPIDurationBuilder
.
Weeks are converted to days before being added (1 week = 7 days).
If the total number of days exceeds 2147483647
(2^31 - 1), a RangeError
is thrown.
The weeks may be negative to perform a subtraction operation, but if the total number of days becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of weeks to add
The mutated builder instance
// '2w'
const span = duration.builder()
.addWeeks(2)
.build();
// true
duration('14d').equals(span)
Adds the given number of years to this DataAPIDurationBuilder
.
Years are converted to months before being added (1 year = 12 months).
If the total number of months exceeds 2147483647
(2^31 - 1), a RangeError
is thrown.
The years may be negative to perform a subtraction operation, but if the total number of months becomes negative, a RangeError
also is thrown. To negate the final result, use the .negate()
method.
The number of years to add
// '2y'
const span = duration.builder()
.addYears(1)
.addYears(1)
.build();
// true
duration('24mo').equals(span)
Builds a new DataAPIDuration
instance from the components added to this DataAPIDurationBuilder
.
May be called at any time to retrieve the current state of the builder as a DataAPIDuration
.
A new DataAPIDuration
instance derived from this DataAPIDurationBuilder
const builder = duration
.builder()
.addYears(1);
// '1y'
const span1 = builder.build().toString();
builder
.negate()
.addMonths(1);
// '-1y1mo'
const span2 = builder.build().toString();
Clones this DataAPIDurationBuilder
instance.
The cloned instance will have the same components as this one, but will be a separate object.
const builder = duration.builder().addYears(1);
const clone = builder.clone();
builder.addMonths(1);
// '1y'
clone.build().toString();
// '1y1mo'
builder.build().toString();
A new DataAPIDurationBuilder
instance with the same components as this one
Negates the final result of this DataAPIDurationBuilder
.
A boolean parameter may be provided to force the sign to be negative/positive—otherwise, it defaults to toggling the sign.
Note that negation does not take place until the .build()
method is called. It simply marks the final result as to-be-negated or not.
Whether to set the sign to negative; defaults to the opposite of the current sign
The mutated builder instance
// '-10h'
const span = duration.builder()
.addHours(10)
.negate()
.build();
// '10h'
const span = duration.builder()
.addHours(10)
.negate(true)
.negate(false)
.build();
Overview
A helpful builder class for manually creating new
DataAPIDuration
instances.Provides methods for incrementally adding duration components, and negating the final result.
Should be instantiated using DataAPIDuration.builder/duration.builder.
Usage
You may call each
.add*()
method any number of times, in any order, before callingbuild
.The
.negate(sign?)
method may be called at any time to negate the final result..negate(sign?)
to definitively set the signA
base
duration may be provided to initialize the builder with its components and its sign.Example
See
DataAPIDuration