UNPKG

1.27 kBTypeScriptView Raw
1import type { GenericDateConstructor } from "./types.js";
2/**
3 * @name transpose
4 * @category Generic Helpers
5 * @summary Transpose the date to the given constructor.
6 *
7 * @description
8 * The function transposes the date to the given constructor. It helps you
9 * to transpose the date in the system time zone to say `UTCDate` or any other
10 * date extension.
11 *
12 * @typeParam DateInputType - The input `Date` type derived from the passed argument.
13 * @typeParam DateOutputType - The output `Date` type derived from the passed constructor.
14 *
15 * @param fromDate - The date to use values from
16 * @param constructor - The date constructor to use
17 *
18 * @returns Date transposed to the given constructor
19 *
20 * @example
21 * // Create July 10, 2022 00:00 in locale time zone
22 * const date = new Date(2022, 6, 10)
23 * //=> 'Sun Jul 10 2022 00:00:00 GMT+0800 (Singapore Standard Time)'
24 *
25 * @example
26 * // Transpose the date to July 10, 2022 00:00 in UTC
27 * transpose(date, UTCDate)
28 * //=> 'Sun Jul 10 2022 00:00:00 GMT+0000 (Coordinated Universal Time)'
29 */
30export declare function transpose<
31 DateInputType extends Date,
32 DateOutputType extends Date,
33>(
34 fromDate: DateInputType,
35 constructor: DateOutputType | GenericDateConstructor<DateOutputType>,
36): DateOutputType;