]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix the second issue
authorSimon Bernier St-Pierre <sbernierstpierre@gmail.com>
Tue, 3 Jun 2014 16:35:21 +0000 (12:35 -0400)
committerSimon Bernier St-Pierre <sbernierstpierre@gmail.com>
Tue, 3 Jun 2014 16:35:21 +0000 (12:35 -0400)
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.

moment.js
test/moment/create.js

index 022f4c161c3a2799bcb04600b6b3d9ff8a3aedec..8364399c4b6c436d0020a4c45c4339180eceb34f 100644 (file)
--- a/moment.js
+++ b/moment.js
     function makeDateFromStringAndFormat(config) {
 
         if (config._f === moment.ISO_8601) {
-            makeDateFromString(config);
+            makeDateFromString(config, false);
             return;
         }
 
     }
 
     // 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++) {
             makeDateFromStringAndFormat(config);
         }
         else {
-            moment.createFromInputFallback(config);
+            if (useFallback) {
+                moment.createFromInputFallback(config);
+            } else {
+                config._isValid = false;
+            }
         }
     }
 
index f67db1c2373184eb7d70504ad190ff46f8216396..58dd776260f9939aeeebda6e05977256c55ea842 100644 (file)
@@ -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();
     },