Skip to main content

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 8601Meaning
P1Y1M1DT1H1M1.1SOne year, one month, one day, one hour, one minute, one second, and 100 milliseconds
P40DForty days
P1Y1DA year and a day
P3DT4H59MThree days, four hours and 59 minutes
PT2H30MTwo and a half hours
P1MOne month
PT1MOne minute
PT0.021S21 milliseconds
PT0SZero
P0DZero
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

iso-types.ts:141

fromNumbers

โ–ธ fromNumbers(years?, months?, weeks?, days?, hours?, minute?, seconds?, milliseconds?): Duration

Parameters

NameType
years?number
months?number
weeks?number
days?number
hours?number
minute?number
seconds?number
milliseconds?number

Returns

Duration

Defined in

types/IDurationFns.ts:5


isValid

โ–ธ isValid(duration): duration is Duration

Parameters

NameType
durationunknown

Returns

duration is Duration

Defined in

types/IDurationFns.ts:15


assertIsValid

โ–ธ assertIsValid(duration): asserts duration is Duration

Parameters

NameType
durationunknown

Returns

asserts duration is Duration

Defined in

types/IDurationFns.ts:16


getYears

โ–ธ getYears(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:17


getMonths

โ–ธ getMonths(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:18


getWeeks

โ–ธ getWeeks(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:19


getDays

โ–ธ getDays(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:20


getHours

โ–ธ getHours(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:21


getMinutes

โ–ธ getMinutes(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:22


getSeconds

โ–ธ getSeconds(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:23


getMilliseconds

โ–ธ getMilliseconds(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:24


getSign

โ–ธ getSign(duration): number

Parameters

NameType
durationDuration

Returns

number

Defined in

types/IDurationFns.ts:25


isBlank

โ–ธ isBlank(duration): boolean

Parameters

NameType
durationDuration

Returns

boolean

Defined in

types/IDurationFns.ts:26


with

โ–ธ with(duration, durationLike): Duration

Parameters

NameType
durationDuration
durationLikeObject
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

Duration

Defined in

types/IDurationFns.ts:27


negated

โ–ธ negated(duration): Duration

Parameters

NameType
durationDuration

Returns

Duration

Defined in

types/IDurationFns.ts:40


abs

โ–ธ abs(duration): Duration

Parameters

NameType
durationDuration

Returns

Duration

Defined in

types/IDurationFns.ts:41


add

โ–ธ add(duration, other, options?): Duration

Parameters

NameType
durationDuration
otherDuration | { years?: number ; months?: number ; weeks?: number ; days?: number ; hours?: number ; minutes?: number ; seconds?: number ; milliseconds?: number }
options?Object
options.relativeToDateTime | ZonedDateTime

Returns

Duration

Defined in

types/IDurationFns.ts:42


subtract

โ–ธ subtract(duration, other, options?): Duration

Parameters

NameType
durationDuration
otherDuration | { years?: number ; months?: number ; weeks?: number ; days?: number ; hours?: number ; minutes?: number ; seconds?: number ; milliseconds?: number }
options?Object
options.relativeToDate | DateTime | ZonedDateTime

Returns

Duration

Defined in

types/IDurationFns.ts:58


round

โ–ธ round(duration, options): Duration

Parameters

NameType
durationDuration
optionsObject
options.largestUnit?TemporalSingularUnit | TemporalPluralUnit | "auto"
options.smallestUnit?TemporalSingularUnit | TemporalPluralUnit
options.roundingIncrement?number
options.roundingMode?TemporalRoundingMode
options.relativeTo?Date | DateTime | ZonedDateTime

Returns

Duration

Defined in

types/IDurationFns.ts:74


total

โ–ธ total(duration, options): number

Parameters

NameType
durationDuration
optionsObject
options.unitTemporalSingularUnit | TemporalPluralUnit
options.relativeTo?Date | DateTime | ZonedDateTime

Returns

number

Defined in

types/IDurationFns.ts:84


getFields

โ–ธ getFields(duration): DurationSlots

Parameters

NameType
durationDuration

Returns

DurationSlots

Defined in

types/IDurationFns.ts:91


from

โ–ธ from(item): Duration

Parameters

NameType
itemany

Returns

Duration

Defined in

types/IDurationFns.ts:92


compare

โ–ธ compare(one, two, options?): number

Parameters

NameType
oneDuration
twoDuration
options?Object
options.relativeToDate | DateTime | ZonedDateTime

Returns

number

Defined in

types/IDurationFns.ts:93


chain

โ–ธ chain(duration): IDurationChain

Parameters

NameType
durationDuration

Returns

IDurationChain

Defined in

types/IDurationFns.ts:98