Get the days.
Get the hours.
Returns an explanation of why this Duration became invalid, or null if the Duration is valid
Returns an error code if this Duration became invalid, or null if the Duration is valid
Returns whether the Duration is invalid. Invalid durations are returned by diff operations on invalid DateTimes or Intervals.
Get the locale of a Duration, such 'en-GB'
Get the milliseconds.
Get the minutes.
Get the months.
Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration
Get the quarters.
Get the seconds.
Get the weeks
Get the years.
Return the length of the duration in the specified unit.
a unit such as 'minutes' or 'days'
Equality check Two Durations are equal iff they have the same units and the same values for each unit.
Get the value of unit.
a unit such as 'minute' or 'day'
Scale this Duration by the specified amount. Return a newly-constructed Duration.
Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
Return the negative of this Duration.
Reduce this Duration to its canonical representation in its current units.
Make this Duration longer by the specified amount. Return a newly-constructed Duration.
The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
"Set" the locale and/or numberingSystem. Returns a newly-constructed Duration.
"Set" the values of specified units. Return a newly-constructed Duration.
a mapping of units to numbers
Convert this Duration into its representation in a different set of units.
Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens:
S
for millisecondss
for secondsm
for minutesh
for hoursd
for daysM
for monthsy
for years
Notes:the format string
options
floor numerical values. Defaults to true.
Returns an ISO 8601-compliant string representation of this Duration.
Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day.
options
Returns an ISO 8601 representation of this Duration appropriate for use in JSON.
Returns an milliseconds value of this Duration.
Returns a JavaScript object with this Duration's values.
Returns an ISO 8601 representation of this Duration appropriate for use in debugging.
Returns an milliseconds value of this Duration. Alias of toMillis
Create a Duration from an ISO 8601 duration string.
text to parse
options for parsing
Create a Duration from an ISO 8601 time string.
text to parse
options for parsing
Create Duration from a number of milliseconds.
of milliseconds
options for parsing
Create a Duration from a JavaScript object with keys like 'years' and 'hours'. If this object is empty then a zero milliseconds duration is returned.
the object to create the DateTime from
options for creating this Duration. Defaults to {}.
Create an invalid Duration.
simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent
longer explanation, may include parameters and other useful debugging information. Defaults to null.
Check if an object is a Duration. Works across context boundaries
Generated using TypeDoc
A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime.plus} to add a Duration object to a DateTime, producing another DateTime.
Here is a brief overview of commonly used methods and getters in Duration:
There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.