/** * Duration units for {@linkcode DifferenceFormat} and * {@linkcode DifferenceOptions}. */ export type Unit = "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "quarters" | "years"; /** Return type for {@linkcode difference}. */ export type DifferenceFormat = Partial>; /** Options for {@linkcode difference}. */ export type DifferenceOptions = { /** * Units to calculate difference in. Defaults to all units. */ units?: Unit[]; }; /** * Calculates the difference of the 2 given dates in various units. If the units * are omitted, it returns the difference in the all available units. * * @param from Year to calculate difference from. * @param to Year to calculate difference to. * @param options Options such as units to calculate difference in. * @returns The difference of the 2 given dates in various units. * * @example Basic usage * ```ts * import { difference } from "@std/datetime/difference"; * import { assertEquals } from "@std/assert"; * * const date0 = new Date("2018-05-14"); * const date1 = new Date("2020-05-13"); * * assertEquals(difference(date0, date1), { * milliseconds: 63072000000, * seconds: 63072000, * minutes: 1051200, * hours: 17520, * days: 730, * weeks: 104, * months: 23, * quarters: 7, * years: 1 * }); * ``` * * @example Calculate difference in specific units * * The `units` option defines which units to calculate the difference in. * * ```ts * import { difference } from "@std/datetime/difference"; * import { assertEquals } from "@std/assert"; * * const date0 = new Date("2018-05-14"); * const date1 = new Date("2020-05-13"); * * const result = difference(date0, date1, { units: ["days", "months", "years"] }); * * assertEquals(result, { * days: 730, * months: 23, * years: 1 * }); * ``` */ export declare function difference(from: Date, to: Date, options?: DifferenceOptions): DifferenceFormat; //# sourceMappingURL=difference.d.ts.map