Skip to content

Commit

Permalink
Merge pull request moment#1897 from ichernev/support-array-with-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Sep 5, 2014
2 parents c4c47a7 + 4bcdf65 commit e89e38d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion moment.js
Expand Up @@ -1557,6 +1557,14 @@
}
}

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) {
Expand All @@ -1568,7 +1576,9 @@
} 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);
Expand Down
8 changes: 8 additions & 0 deletions test/moment/create.js
Expand Up @@ -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();
}

};

0 comments on commit e89e38d

Please sign in to comment.