Duration
ฦฌ Duration: Format["P(n)Y(n)M(n)DT(n)H(n)M(n)S"] & string
A Iso.Duration represents a duration of time which can be used in date/time arithmetic.
Iso.Duration can be constructed directly or returned from durationFns.from(). It can also be obtained from the since() function of any other Iso type that supports arithmetic, and is used in those types' add() and subtract() functions.
An Iso.Duration is a string according to the ISO 8601 notation for durations. The examples in this page use this notation extensively.
Briefly, the ISO 8601 notation consists of a P character, followed by years, months, weeks, and days, followed by a T character, followed by hours, minutes, and seconds with a decimal part, each with a single-letter suffix that indicates the unit. Any zero components may be omitted. For more detailed information, see the ISO 8601 standard or the Wikipedia page.
| ISO 8601 | Meaning |
|---|---|
| P1Y1M1DT1H1M1.1S | One year, one month, one day, one hour, one minute, one second, and 100 milliseconds |
| P40D | Forty days |
| P1Y1D | A year and a day |
| P3DT4H59M | Three days, four hours and 59 minutes |
| PT2H30M | Two and a half hours |
| P1M | One month |
| PT1M | One minute |
| PT0.021S | 21 milliseconds |
| PT0S | Zero |
| P0D | Zero |
note
According to the ISO 8601-1 standard, weeks are not allowed to appear together with any other units, and durations can only be positive. As extensions to the standard, ISO 8601-2 allows a sign character at the start of the string, and allows combining weeks with other units. If you intend to use a string such as P3W1D, +P1M, or -P1M for interoperability, note that other programs may not accept it.
Defined in
fromNumbers
โธ fromNumbers(years?, months?, weeks?, days?, hours?, minute?, seconds?, milliseconds?): Duration
Parameters
| Name | Type |
|---|---|
years? | number |
months? | number |
weeks? | number |
days? | number |
hours? | number |
minute? | number |
seconds? | number |
milliseconds? | number |
Returns
Defined in
isValid
โธ isValid(duration): duration is Duration
Parameters
| Name | Type |
|---|---|
duration | unknown |
Returns
duration is Duration
Defined in
assertIsValid
โธ assertIsValid(duration): asserts duration is Duration
Parameters
| Name | Type |
|---|---|
duration | unknown |
Returns
asserts duration is Duration
Defined in
getYears
โธ getYears(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getMonths
โธ getMonths(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getWeeks
โธ getWeeks(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getDays
โธ getDays(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getHours
โธ getHours(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getMinutes
โธ getMinutes(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getSeconds
โธ getSeconds(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getMilliseconds
โธ getMilliseconds(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
getSign
โธ getSign(duration): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
number
Defined in
isBlank
โธ isBlank(duration): boolean
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
boolean
Defined in
with
โธ with(duration, durationLike): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
durationLike | Object |
durationLike.years? | number |
durationLike.months? | number |
durationLike.weeks? | number |
durationLike.days? | number |
durationLike.hours? | number |
durationLike.minutes? | number |
durationLike.seconds? | number |
durationLike.milliseconds? | number |
Returns
Defined in
negated
โธ negated(duration): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
Defined in
abs
โธ abs(duration): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
Defined in
add
โธ add(duration, other, options?): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
other | Duration | { years?: number ; months?: number ; weeks?: number ; days?: number ; hours?: number ; minutes?: number ; seconds?: number ; milliseconds?: number } |
options? | Object |
options.relativeTo | DateTime | ZonedDateTime |
Returns
Defined in
subtract
โธ subtract(duration, other, options?): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
other | Duration | { years?: number ; months?: number ; weeks?: number ; days?: number ; hours?: number ; minutes?: number ; seconds?: number ; milliseconds?: number } |
options? | Object |
options.relativeTo | Date | DateTime | ZonedDateTime |
Returns
Defined in
round
โธ round(duration, options): Duration
Parameters
| Name | Type |
|---|---|
duration | Duration |
options | Object |
options.largestUnit? | TemporalSingularUnit | TemporalPluralUnit | "auto" |
options.smallestUnit? | TemporalSingularUnit | TemporalPluralUnit |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
options.relativeTo? | Date | DateTime | ZonedDateTime |
Returns
Defined in
total
โธ total(duration, options): number
Parameters
| Name | Type |
|---|---|
duration | Duration |
options | Object |
options.unit | TemporalSingularUnit | TemporalPluralUnit |
options.relativeTo? | Date | DateTime | ZonedDateTime |
Returns
number
Defined in
getFields
โธ getFields(duration): DurationSlots
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
DurationSlots
Defined in
from
โธ from(item): Duration
Parameters
| Name | Type |
|---|---|
item | any |
Returns
Defined in
compare
โธ compare(one, two, options?): number
Parameters
| Name | Type |
|---|---|
one | Duration |
two | Duration |
options? | Object |
options.relativeTo | Date | DateTime | ZonedDateTime |
Returns
number
Defined in
chain
โธ chain(duration): IDurationChain
Parameters
| Name | Type |
|---|---|
duration | Duration |
Returns
IDurationChain