UNPKG

1.15 kBTypeScriptView Raw
1/**
2 * @name toDate
3 * @category Common Helpers
4 * @summary Convert the given argument to an instance of Date.
5 *
6 * @description
7 * Convert the given argument to an instance of Date.
8 *
9 * If the argument is an instance of Date, the function returns its clone.
10 *
11 * If the argument is a number, it is treated as a timestamp.
12 *
13 * If the argument is none of the above, the function returns Invalid Date.
14 *
15 * **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
16 *
17 * @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).
18 *
19 * @param argument - The value to convert
20 *
21 * @returns The parsed date in the local time zone
22 *
23 * @example
24 * // Clone the date:
25 * const result = toDate(new Date(2014, 1, 11, 11, 30, 30))
26 * //=> Tue Feb 11 2014 11:30:30
27 *
28 * @example
29 * // Convert the timestamp to date:
30 * const result = toDate(1392098430000)
31 * //=> Tue Feb 11 2014 11:30:30
32 */
33export declare function toDate<DateType extends Date>(
34 argument: DateType | number | string,
35): DateType;