UNPKG

1.63 kBTypeScriptView Raw
1import type { Duration } from "./types.js";
2/**
3 * @name sub
4 * @category Common Helpers
5 * @summary Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
6 *
7 * @description
8 * Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
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 date - The date to be changed
13 * @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be subtracted
14 *
15 * | Key | Description |
16 * |---------|------------------------------------|
17 * | years | Amount of years to be subtracted |
18 * | months | Amount of months to be subtracted |
19 * | weeks | Amount of weeks to be subtracted |
20 * | days | Amount of days to be subtracted |
21 * | hours | Amount of hours to be subtracted |
22 * | minutes | Amount of minutes to be subtracted |
23 * | seconds | Amount of seconds to be subtracted |
24 *
25 * All values default to 0
26 *
27 * @returns The new date with the seconds subtracted
28 *
29 * @example
30 * // Subtract the following duration from 15 June 2017 15:29:20
31 * const result = sub(new Date(2017, 5, 15, 15, 29, 20), {
32 * years: 2,
33 * months: 9,
34 * weeks: 1,
35 * days: 7,
36 * hours: 5,
37 * minutes: 9,
38 * seconds: 30
39 * })
40 * //=> Mon Sep 1 2014 10:19:50
41 */
42export declare function sub<DateType extends Date>(
43 date: DateType | number | string,
44 duration: Duration,
45): DateType;