]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] isoWeeksInYear was modifying the source object (#5474)
authorIskren Ivov Chernev <iskren.chernev@gmail.com>
Wed, 29 Apr 2020 15:20:04 +0000 (18:20 +0300)
committerGitHub <noreply@github.com>
Wed, 29 Apr 2020 15:20:04 +0000 (18:20 +0300)
src/lib/units/week-year.js
src/test/moment/weeks_in_year.js

index daf5af70dcdd016de7afddbaac5adb64c818b6e4..7c60a364593497ab9636c9e943c1342ea70fd958 100644 (file)
@@ -21,10 +21,6 @@ import toInt from '../utils/to-int';
 import { hooks } from '../utils/hooks';
 import { createUTCDate } from '../create/date-from-array';
 
-// CONSTANTS
-
-const THURSDAY = 4;
-
 // FORMATTING
 
 addFormatToken(0, ['gg', 2], 0, function () {
@@ -103,7 +99,7 @@ export function getSetISOWeekYear(input) {
 }
 
 export function getISOWeeksInYear() {
-    return weeksInYear(this.isoWeekday(THURSDAY).year(), 1, 4);
+    return weeksInYear(this.isoWeekYear(), 1, 4);
 }
 
 export function getWeeksInYear() {
index b8bef36125e2093da3d008fbe8770f48b721f53f..b2a50057bc15ab0e3ba79f9c98fc8103437f5e7c 100644 (file)
@@ -177,6 +177,7 @@ test('weeksInYear doy/dow = 0/6', function (assert) {
 });
 
 test('isoWeeksInYear calendar year !== ISO year', function (assert) {
+    var m = moment('2010-01-01');
     assert.equal(
         moment('2019-12-31').isoWeeksInYear(),
         53,
@@ -187,4 +188,14 @@ test('isoWeeksInYear calendar year !== ISO year', function (assert) {
         53,
         'December 31, 2020 is in ISO year 2020 and ISO year 2020 has 53 weeks'
     );
+    assert.equal(
+        m.isoWeeksInYear(),
+        53,
+        '2010-01-01 is isoWeekYear 2009, which has 53 iso weeks'
+    );
+    assert.equal(
+        +m,
+        +moment('2010-01-01'),
+        'isoWeeksInYear does not modify moment object'
+    );
 });