set.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { DateValues } from "./types.js";
  2. /**
  3. * @name set
  4. * @category Common Helpers
  5. * @summary Set date values to a given date.
  6. *
  7. * @description
  8. * Set date values to a given date.
  9. *
  10. * Sets time values to date from object `values`.
  11. * A value is not set if it is undefined or null or doesn't exist in `values`.
  12. *
  13. * Note about bundle size: `set` does not internally use `setX` functions from date-fns but instead opts
  14. * to use native `Date#setX` methods. If you use this function, you may not want to include the
  15. * other `setX` functions that date-fns provides if you are concerned about the bundle size.
  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 date - The date to be changed
  20. * @param values - The date values to be set
  21. *
  22. * @returns The new date with options set
  23. *
  24. * @example
  25. * // Transform 1 September 2014 into 20 October 2015 in a single line:
  26. * const result = set(new Date(2014, 8, 20), { year: 2015, month: 9, date: 20 })
  27. * //=> Tue Oct 20 2015 00:00:00
  28. *
  29. * @example
  30. * // Set 12 PM to 1 September 2014 01:23:45 to 1 September 2014 12:00:00:
  31. * const result = set(new Date(2014, 8, 1, 1, 23, 45), { hours: 12 })
  32. * //=> Mon Sep 01 2014 12:23:45
  33. */
  34. export declare function set<DateType extends Date>(
  35. date: DateType | number | string,
  36. values: DateValues,
  37. ): DateType;