index.js 870 B

12345678910111213141516
  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; // This function will be a part of public API when UTC function will be implemented.
  6. // See issue: https://github.com/date-fns/date-fns/issues/376
  7. export default function getUTCISOWeek(dirtyDate) {
  8. requiredArgs(1, arguments);
  9. var date = toDate(dirtyDate);
  10. var diff = startOfUTCISOWeek(date).getTime() - startOfUTCISOWeekYear(date).getTime(); // 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. }