transpose.d.cts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type { ContextFn, 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 InputDate - The input `Date` type derived from the passed argument.
  13. * @typeParam ResultDate - The result `Date` type derived from the passed constructor.
  14. *
  15. * @param date - 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. */
  30. export declare function transpose<
  31. InputDate extends Date,
  32. ResultDate extends Date,
  33. >(
  34. date: InputDate,
  35. constructor:
  36. | ResultDate
  37. | GenericDateConstructor<ResultDate>
  38. | ContextFn<ResultDate>,
  39. ): ResultDate;