differenceInWeeks.d.cts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type { ContextOptions, DateArg, RoundingOptions } from "./types.js";
  2. /**
  3. * The {@link differenceInWeeks} function options.
  4. */
  5. export interface DifferenceInWeeksOptions
  6. extends RoundingOptions,
  7. ContextOptions<Date> {}
  8. /**
  9. * @name differenceInWeeks
  10. * @category Week Helpers
  11. * @summary Get the number of full weeks between the given dates.
  12. *
  13. * @description
  14. * Get the number of full weeks between two dates. Fractional weeks are
  15. * truncated towards zero by default.
  16. *
  17. * One "full week" is the distance between a local time in one day to the same
  18. * local time 7 days earlier or later. A full week can sometimes be less than
  19. * or more than 7*24 hours if a daylight savings change happens between two dates.
  20. *
  21. * To ignore DST and only measure exact 7*24-hour periods, use this instead:
  22. * `Math.trunc(differenceInHours(dateLeft, dateRight)/(7*24))|0`.
  23. *
  24. * @param laterDate - The later date
  25. * @param earlierDate - The earlier date
  26. * @param options - An object with options
  27. *
  28. * @returns The number of full weeks
  29. *
  30. * @example
  31. * // How many full weeks are between 5 July 2014 and 20 July 2014?
  32. * const result = differenceInWeeks(new Date(2014, 6, 20), new Date(2014, 6, 5))
  33. * //=> 2
  34. *
  35. * @example
  36. * // How many full weeks are between
  37. * // 1 March 2020 0:00 and 6 June 2020 0:00 ?
  38. * // Note: because local time is used, the
  39. * // result will always be 8 weeks (54 days),
  40. * // even if DST starts and the period has
  41. * // only 54*24-1 hours.
  42. * const result = differenceInWeeks(
  43. * new Date(2020, 5, 1),
  44. * new Date(2020, 2, 6)
  45. * )
  46. * //=> 8
  47. */
  48. export declare function differenceInWeeks(
  49. laterDate: DateArg<Date> & {},
  50. earlierDate: DateArg<Date> & {},
  51. options?: DifferenceInWeeksOptions | undefined,
  52. ): number;