1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = isSameWeek;
|
7 |
|
8 | var _index = _interopRequireDefault(require("../startOfWeek/index.js"));
|
9 |
|
10 | var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | /**
|
15 | * @name isSameWeek
|
16 | * @category Week Helpers
|
17 | * @summary Are the given dates in the same week?
|
18 | *
|
19 | * @description
|
20 | * Are the given dates in the same week?
|
21 | *
|
22 | * ### v2.0.0 breaking changes:
|
23 | *
|
24 | * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
25 | *
|
26 | * @param {Date|Number} dateLeft - the first date to check
|
27 | * @param {Date|Number} dateRight - the second date to check
|
28 | * @param {Object} [options] - an object with options.
|
29 | * @param {Locale} [options.locale=defaultLocale] - the locale object. See [Locale]{@link https://date-fns.org/docs/Locale}
|
30 | * @param {0|1|2|3|4|5|6} [options.weekStartsOn=0] - the index of the first day of the week (0 - Sunday)
|
31 | * @returns {Boolean} the dates are in the same week
|
32 | * @throws {TypeError} 2 arguments required
|
33 | * @throws {RangeError} `options.weekStartsOn` must be between 0 and 6
|
34 | *
|
35 | * @example
|
36 | * // Are 31 August 2014 and 4 September 2014 in the same week?
|
37 | * var result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4))
|
38 | * //=> true
|
39 | *
|
40 | * @example
|
41 | * // If week starts with Monday,
|
42 | * // are 31 August 2014 and 4 September 2014 in the same week?
|
43 | * var result = isSameWeek(new Date(2014, 7, 31), new Date(2014, 8, 4), {
|
44 | * weekStartsOn: 1
|
45 | * })
|
46 | * //=> false
|
47 | */
|
48 | function isSameWeek(dirtyDateLeft, dirtyDateRight, dirtyOptions) {
|
49 | (0, _index2.default)(2, arguments);
|
50 | var dateLeftStartOfWeek = (0, _index.default)(dirtyDateLeft, dirtyOptions);
|
51 | var dateRightStartOfWeek = (0, _index.default)(dirtyDateRight, dirtyOptions);
|
52 | return dateLeftStartOfWeek.getTime() === dateRightStartOfWeek.getTime();
|
53 | }
|
54 |
|
55 | module.exports = exports.default; |
\ | No newline at end of file |