]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Moment creation with array of string now works properly 1897/head
authorIskren Chernev <iskren.chernev@gmail.com>
Fri, 29 Aug 2014 16:25:25 +0000 (19:25 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 29 Aug 2014 16:27:06 +0000 (19:27 +0300)
moment.js
test/moment/create.js

index da8fb8969103a55f047e007c952431cbf73435b4..868206aadfba8555ad22a6522ecc9517ee7bcba6 100644 (file)
--- a/moment.js
+++ b/moment.js
         }
     }
 
+    function map(arr, fn) {
+        var res = [], i;
+        for (i = 0; i < arr.length; ++i) {
+            res.push(fn(arr[i], i));
+        }
+        return res;
+    }
+
     function makeDateFromInput(config) {
         var input = config._i, matched;
         if (input === undefined) {
         } else if (typeof input === 'string') {
             makeDateFromString(config);
         } else if (isArray(input)) {
-            config._a = input.slice(0);
+            config._a = map(input.slice(0), function (obj) {
+                return parseInt(obj, 10);
+            });
             dateFromConfig(config);
         } else if (typeof(input) === 'object') {
             dateFromObject(config);
index d5d38756f8a8151efdbae27f3bf49e488eb655f9..a141d669b9700d60079fbdf689973a67f54b6667 100644 (file)
@@ -936,5 +936,13 @@ exports.create = {
             moment.parseTwoDigitYear = original;
             test.done();
         }
+    },
+
+    'array with strings' : function (test) {
+        test.equal(moment(['2014', '7', '31']).isValid(),
+                true,
+                'string array + isValid');
+        test.done();
     }
+
 };