]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing #152
authorTim Wood <washwithcare@gmail.com>
Thu, 2 Feb 2012 16:24:03 +0000 (08:24 -0800)
committerTim Wood <washwithcare@gmail.com>
Thu, 2 Feb 2012 16:24:03 +0000 (08:24 -0800)
Typecasting string to number on `moment().add('days', '2')`

moment.js
sitesrc/js/unit-tests.js

index dda6d16b0e6f35d1cdeeacd2da5d6d0fecb23bcf..c787148031f96f69c6711060dc97d6699cf24448 100644 (file)
--- 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
index 1765356eb478d99b1cd6f9af53114da20f1f757b..626a93cd8b140f9bad9ca844670b7a877df55b25 100755 (executable)
@@ -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() {