O3 Framework / duration
duration(
startDate,endDate,options?):null|DurationInput
Defined in: packages/framework/esm-utils/src/dates/date-util.ts:645
Calculates the duration between two dates as a structured duration object.
When called with no options or a single unit string, the unit is auto-selected using dayjs relativeTime thresholds:
With a DurationOptions object, you can override thresholds and/or request a multi-unit decomposition via largestUnit/smallestUnit.
ConfigType
The start date. If null, returns null.
ConfigType = ...
Optional. Defaults to now.
A unit string for single-unit output, or a DurationOptions object.
DurationUnit |
DurationOptions |
null | DurationInput
A DurationInput object, or null if either date is null or unparseable.
// Auto-selects the appropriate unit
duration('2022-01-01', '2024-07-30') // => { years: 2 }
// Multi-unit decomposition
duration('2022-01-01', '2024-07-30', { largestUnit: 'year', smallestUnit: 'day' })
// => { years: 2, months: 6, days: 29 }