daysToWeeks.js 719 B

1234567891011121314151617181920212223242526272829303132
  1. import { daysInWeek } from "./constants.js";
  2. /**
  3. * @name daysToWeeks
  4. * @category Conversion Helpers
  5. * @summary Convert days to weeks.
  6. *
  7. * @description
  8. * Convert a number of days to a full number of weeks.
  9. *
  10. * @param days - The number of days to be converted
  11. *
  12. * @returns The number of days converted in weeks
  13. *
  14. * @example
  15. * // Convert 14 days to weeks:
  16. * const result = daysToWeeks(14)
  17. * //=> 2
  18. *
  19. * @example
  20. * // It uses trunc rounding:
  21. * const result = daysToWeeks(13)
  22. * //=> 1
  23. */
  24. export function daysToWeeks(days) {
  25. const result = Math.trunc(days / daysInWeek);
  26. // Prevent negative zero
  27. return result === 0 ? 0 : result;
  28. }
  29. // Fallback for modularized imports:
  30. export default daysToWeeks;