index.js 646 B

123456789101112131415
  1. import toDate from "../../toDate/index.js";
  2. import requiredArgs from "../requiredArgs/index.js";
  3. var MILLISECONDS_IN_DAY = 86400000; // This function will be a part of public API when UTC function will be implemented.
  4. // See issue: https://github.com/date-fns/date-fns/issues/376
  5. export default function getUTCDayOfYear(dirtyDate) {
  6. requiredArgs(1, arguments);
  7. var date = toDate(dirtyDate);
  8. var timestamp = date.getTime();
  9. date.setUTCMonth(0, 1);
  10. date.setUTCHours(0, 0, 0, 0);
  11. var startOfYearTimestamp = date.getTime();
  12. var difference = timestamp - startOfYearTimestamp;
  13. return Math.floor(difference / MILLISECONDS_IN_DAY) + 1;
  14. }