daysToWeeks.cjs 698 B

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