Constructs a duration.
The resulting duration will be simplified. For example 12 months will become 1 year and 0 months.
From component values.
const duration = new Duration(2, 14, 0, 0, 24)
console.log(duration.toString())
// P3Y2M1D
From a string.
const duration = new Duration('P2Y14MT24H')
console.log(duration.toString())
// P3Y2M1D
From a value.
const duration = new Duration(98582400)
console.log(duration.toString())
// P3Y2M1D
The years.
The months.
The weeks.
The days.
The hours.
The minutes.
The seconds.
Constructs a year from the string representation, the number of seconds, or another duration object.
The resulting duration will be simplified. For example 12 months will become 1 year and 0 months.
From component values.
const duration = new Duration(2, 14, 0, 0, 24)
console.log(duration.toString())
// P3Y2M1D
From a string.
const duration = new Duration('P2Y14MT24H')
console.log(duration.toString())
// P3Y2M1D
From a value.
const duration = new Duration(98582400)
console.log(duration.toString())
// P3Y2M1D
The duration as a string, number, or duration.
Gets the days.
Sets the days.
If the value is greater than or equal to 7 the duration is simplified.
Gets the hours.
Sets the hours.
If the value is greater than or equal to 24 the duration is simplified.
Gets the minutes.
Sets the minutes.
If the value is greater than or equal to 60 the duration is simplified.
Gets the months.
Sets the months.
If the value is greater than or equal to 12 the duration is simplified.
Gets the seconds.
Sets the seconds.
If the value is greater than or equal to 60 the value is simplified.
Gets the weeks.
Sets the weeks.
Gets the years.
Sets the years.
Creates a string representation of the duration.
An ISO 8601 duration.
The number of milliseconds of the duration assuming a year has 360 days and a month has 30 days.
Note that this is not idempotent. As the actual number of days in a year is not available, constant values are used. This means that 30 days is equivalent to a month.
const d1 = new Duration('P1M')
console.log(d1.valueOf())
// 2592000
const d2 = new Duration('P30D')
console.log(d1.valueOf())
// 2592000
The number of milliseconds to which the duration corresponds.
Generated using TypeDoc
Represents an ISO 8601 duration.
Here we add a day.
Note that durations may be negative.