index.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getUTCWeek;
  6. var _index = _interopRequireDefault(require("../../toDate/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfUTCWeek/index.js"));
  8. var _index3 = _interopRequireDefault(require("../startOfUTCWeekYear/index.js"));
  9. var _index4 = _interopRequireDefault(require("../requiredArgs/index.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. var MILLISECONDS_IN_WEEK = 604800000; // This function will be a part of public API when UTC function will be implemented.
  12. // See issue: https://github.com/date-fns/date-fns/issues/376
  13. function getUTCWeek(dirtyDate, options) {
  14. (0, _index4.default)(1, arguments);
  15. var date = (0, _index.default)(dirtyDate);
  16. var diff = (0, _index2.default)(date, options).getTime() - (0, _index3.default)(date, options).getTime(); // Round the number of days to the nearest integer
  17. // because the number of milliseconds in a week is not constant
  18. // (e.g. it's different in the week of the daylight saving time clock shift)
  19. return Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
  20. }
  21. module.exports = exports.default;