1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = differenceInCalendarISOWeeks;
|
7 |
|
8 | var _index = _interopRequireDefault(require("../_lib/getTimezoneOffsetInMilliseconds/index.js"));
|
9 |
|
10 | var _index2 = _interopRequireDefault(require("../startOfISOWeek/index.js"));
|
11 |
|
12 | var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 | var MILLISECONDS_IN_WEEK = 604800000;
|
17 | /**
|
18 | * @name differenceInCalendarISOWeeks
|
19 | * @category ISO Week Helpers
|
20 | * @summary Get the number of calendar ISO weeks between the given dates.
|
21 | *
|
22 | * @description
|
23 | * Get the number of calendar ISO weeks between the given dates.
|
24 | *
|
25 | * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
|
26 | *
|
27 | * ### v2.0.0 breaking changes:
|
28 | *
|
29 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
30 | *
|
31 | * @param {Date|Number} dateLeft - the later date
|
32 | * @param {Date|Number} dateRight - the earlier date
|
33 | * @returns {Number} the number of calendar ISO weeks
|
34 | * @throws {TypeError} 2 arguments required
|
35 | *
|
36 | * @example
|
37 | * // How many calendar ISO weeks are between 6 July 2014 and 21 July 2014?
|
38 | * var result = differenceInCalendarISOWeeks(
|
39 | * new Date(2014, 6, 21),
|
40 | * new Date(2014, 6, 6)
|
41 | * )
|
42 | * //=> 3
|
43 | */
|
44 |
|
45 | function differenceInCalendarISOWeeks(dirtyDateLeft, dirtyDateRight) {
|
46 | (0, _index3.default)(2, arguments);
|
47 | var startOfISOWeekLeft = (0, _index2.default)(dirtyDateLeft);
|
48 | var startOfISOWeekRight = (0, _index2.default)(dirtyDateRight);
|
49 | var timestampLeft = startOfISOWeekLeft.getTime() - (0, _index.default)(startOfISOWeekLeft);
|
50 | var timestampRight = startOfISOWeekRight.getTime() - (0, _index.default)(startOfISOWeekRight); // Round the number of days to the nearest integer
|
51 | // because the number of milliseconds in a week is not constant
|
52 | // (e.g. it's different in the week of the daylight saving time clock shift)
|
53 |
|
54 | return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_WEEK);
|
55 | }
|
56 |
|
57 | module.exports = exports.default; |
\ | No newline at end of file |