index.js 724 B

123456789101112131415
  1. import toDate from "../../toDate/index.js";
  2. import startOfUTCISOWeek from "../startOfUTCISOWeek/index.js";
  3. import startOfUTCISOWeekYear from "../startOfUTCISOWeekYear/index.js";
  4. import requiredArgs from "../requiredArgs/index.js";
  5. var MILLISECONDS_IN_WEEK = 604800000;
  6. export default function getUTCISOWeek(dirtyDate) {
  7. requiredArgs(1, arguments);
  8. var date = toDate(dirtyDate);
  9. var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime();
  10. // Round the number of days to the nearest integer
  11. // because the number of milliseconds in a week is not constant
  12. // (e.g. it's different in the week of the daylight saving time clock shift)
  13. return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
  14. }