]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
parse string arguments for month() correctly, closes #2884
authorAndrew Kolesnikov <hello@andrewkolesnikov.com>
Thu, 14 Jan 2016 09:12:13 +0000 (16:12 +0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 6 Mar 2016 08:56:32 +0000 (00:56 -0800)
src/lib/units/month.js
src/test/moment/getters_setters.js

index 60806d6d05152e2d8e7a29f4b0c67c718b0c3417..2152afe53224c4f5f26a452837230ff0290a2c6d 100644 (file)
@@ -115,7 +115,7 @@ export function setMonth (mom, value) {
     }
 
     // TODO: Move this out of here!
-    if (typeof value === 'string') {
+    if (typeof value === 'string' && !/^\d+$/.test(value)) {
         value = mom.localeData().monthsParse(value);
         // TODO: Another silent failure?
         if (typeof value !== 'number') {
index c8c9c967231958bbe0a4c9307a4c2b788de0debe..44598b0b5f546dac0dbbe9fe3663a31076773e64 100644 (file)
@@ -236,3 +236,22 @@ test('day setter', function (assert) {
     assert.equal(moment(a).day(20).date(), 29, 'set from wednesday to second next saturday');
     assert.equal(moment(a).day(17).date(), 26, 'set from wednesday to second next wednesday');
 });
+
+test('string setters', function (assert) {
+    var a = moment();
+    a.year('2011');
+    a.month('9');
+    a.date('12');
+    a.hours('6');
+    a.minutes('7');
+    a.seconds('8');
+    a.milliseconds('9');
+    assert.equal(a.year(), 2011, 'year');
+    assert.equal(a.month(), 9, 'month');
+    assert.equal(a.date(), 12, 'date');
+    assert.equal(a.day(), 3, 'day');
+    assert.equal(a.hours(), 6, 'hour');
+    assert.equal(a.minutes(), 7, 'minute');
+    assert.equal(a.seconds(), 8, 'second');
+    assert.equal(a.milliseconds(), 9, 'milliseconds');
+});