UNPKG

896 BTypeScriptView Raw
1import type { Duration, Interval } from "./types.js";
2/**
3 * @name intervalToDuration
4 * @category Common Helpers
5 * @summary Convert interval to duration
6 *
7 * @description
8 * Convert a interval object to a duration object.
9 *
10 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
11 *
12 * @param interval - The interval to convert to duration
13 *
14 * @returns The duration object
15 *
16 * @example
17 * // Get the duration between January 15, 1929 and April 4, 1968.
18 * intervalToDuration({
19 * start: new Date(1929, 0, 15, 12, 0, 0),
20 * end: new Date(1968, 3, 4, 19, 5, 0)
21 * })
22 * // => { years: 39, months: 2, days: 20, hours: 7, minutes: 5, seconds: 0 }
23 */
24export declare function intervalToDuration<DateType extends Date>(
25 interval: Interval<DateType>,
26): Duration;