From: Tim Wood Date: Thu, 2 Feb 2012 16:24:03 +0000 (-0800) Subject: Fixing #152 X-Git-Tag: 1.4.0~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e3837523fc25deff5d38d9c417d97c8a4d0ae20;p=thirdparty%2Fmoment.git Fixing #152 Typecasting string to number on `moment().add('days', '2')` --- diff --git a/moment.js b/moment.js index dda6d16b0..c78714803 100644 --- a/moment.js +++ b/moment.js @@ -46,7 +46,7 @@ input = isString ? {} : _input, ms, d, M, currentDate; if (isString && val) { - input[_input] = val; + input[_input] = +val; } ms = (input.ms || input.milliseconds || 0) + (input.s || input.seconds || 0) * 1e3 + // 1000 diff --git a/sitesrc/js/unit-tests.js b/sitesrc/js/unit-tests.js index 1765356eb..626a93cd8 100755 --- a/sitesrc/js/unit-tests.js +++ b/sitesrc/js/unit-tests.js @@ -196,7 +196,7 @@ test("add and subtract long", 8, function() { equal(a.add({years:1}).year(), 2012, 'Add year'); }); -test("add and subtract string short", 8, function() { +test("add and subtract string short", 9, function() { var a = moment(); a.year(2011); a.month(9); @@ -206,6 +206,8 @@ test("add and subtract string short", 8, function() { a.seconds(8); a.milliseconds(500); + var b = a.clone(); + equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds'); equal(a.add('seconds', 1).seconds(), 9, 'Add seconds'); equal(a.add('minutes', 1).minutes(), 8, 'Add minutes'); @@ -214,6 +216,7 @@ test("add and subtract string short", 8, function() { equal(a.add('weeks', 1).date(), 20, 'Add week'); equal(a.add('months', 1).month(), 10, 'Add month'); equal(a.add('years', 1).year(), 2012, 'Add year'); + equal(b.add('days', '01').date(), 13, 'Add date'); }); test("add and subtract string short", 8, function() {