From: Simon Bernier St-Pierre Date: Tue, 3 Jun 2014 16:35:21 +0000 (-0400) Subject: Fix the second issue X-Git-Tag: 2.7.0~3^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c9fb2769eda7d6a5919d01be3b2ed9ede162667;p=thirdparty%2Fmoment.git Fix the second issue I've added a useFallback parameter to makeDateFromString. When not supplied, the old behavior remains. When supplied and true, it does not call the createFromInputCallback and instead returns an empty config. This also seems to fix the first issue, it now plays much nicer with scoring and precendence. --- diff --git a/moment.js b/moment.js index 022f4c161..8364399c4 100644 --- a/moment.js +++ b/moment.js @@ -1345,7 +1345,7 @@ function makeDateFromStringAndFormat(config) { if (config._f === moment.ISO_8601) { - makeDateFromString(config); + makeDateFromString(config, false); return; } @@ -1461,11 +1461,13 @@ } // date from iso format - function makeDateFromString(config) { + function makeDateFromString(config, useFallback) { var i, l, string = config._i, match = isoRegex.exec(string); + useFallback = typeof useFallback === 'undefined' ? true : useFallback; + if (match) { config._pf.iso = true; for (i = 0, l = isoDates.length; i < l; i++) { @@ -1487,7 +1489,11 @@ makeDateFromStringAndFormat(config); } else { - moment.createFromInputFallback(config); + if (useFallback) { + moment.createFromInputFallback(config); + } else { + config._isValid = false; + } } } diff --git a/test/moment/create.js b/test/moment/create.js index f67db1c23..58dd77626 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -399,11 +399,12 @@ exports.create = { function parseISO(string) { return moment(string, ['YYYY', 'HH:mm', 'M', moment.ISO_8601]); } - // those tests are broken because of the scoring system - // and the deprecation of createFromInputFallback - //test.equal(parseISO('1994').year(), 1994, 'iso: test parse year'); - //test.equal(parseISO('17:15').format('HH:mm'), '17:15', 'iso: test parse HH:mm'); + test.equal(parseISO('1994').year(), 1994, 'iso: test parse year'); + test.equal(parseISO('17:15').format('HH:mm'), '17:15', 'iso: test parse HH:mm'); test.equal(parseISO('2012-06-01').format('YYYY-MM-DD'), '2012-06-01', 'iso: test parse iso'); + + test.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD'])._pf.iso, true, 'iso: edge case array precedence iso'); + test.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601])._pf.iso, false, 'iso: edge case array precedence not iso'); test.done(); },