From: John Crisostomo Date: Sat, 29 Oct 2016 09:18:16 +0000 (+0800) Subject: fixes issue #3529 X-Git-Tag: 2.16.0~19^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=055bd6b05e3e9fdbeef8cfb24e42bf9523af501a;p=thirdparty%2Fmoment.git fixes issue #3529 --- diff --git a/src/lib/create/from-anything.js b/src/lib/create/from-anything.js index 4615090c9..11e15089d 100644 --- a/src/lib/create/from-anything.js +++ b/src/lib/create/from-anything.js @@ -43,10 +43,10 @@ export function prepareConfig (config) { if (isMoment(input)) { return new Moment(checkOverflow(input)); - } else if (isArray(format)) { - configFromStringAndArray(config); } else if (isDate(input)) { config._d = input; + } else if (isArray(format)) { + configFromStringAndArray(config); } else if (format) { configFromStringAndFormat(config); } else { diff --git a/src/test/moment/create.js b/src/test/moment/create.js index 7dc7a5085..f5f2e6fc0 100644 --- a/src/test/moment/create.js +++ b/src/test/moment/create.js @@ -75,6 +75,20 @@ test('date', function (assert) { assert.equal(moment(new Date(2016,0,1), 'YYYY-MM-DD').format('YYYY-MM-DD'), '2016-01-01', 'If date is provided, format string is ignored'); }); +test('date with a format as an array', function (assert) { + var tests = [ + new Date(2016, 9, 27), + new Date(2016, 9, 28), + new Date(2016, 9, 29), + new Date(2016, 9, 30), + new Date(2016, 9, 31) + ], i; + + for (i = 0; i < tests.length; i++) { + assert.equal(moment(tests[i]).format(), moment(tests[i], ['MM/DD/YYYY'], false).format(), 'Passing date with a format array should still return the correct date'); + } +}); + test('date mutation', function (assert) { var a = new Date(); assert.ok(moment(a).toDate() !== a, 'the date moment uses should not be the date passed in');