]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
skippedInput + trailingInput = unusedInput
authorIsaac Cambron <isaac@isaaccambron.com>
Fri, 27 Sep 2013 21:20:02 +0000 (17:20 -0400)
committerIsaac Cambron <isaac@isaaccambron.com>
Fri, 27 Sep 2013 21:20:02 +0000 (17:20 -0400)
moment.js
test/moment.parsing_flags.js

index 322f43bd7be78d19af83ee12ddf70c422e113c31..e080bbdfb460e81b264307165a176d9bc6b77506 100644 (file)
--- a/moment.js
+++ b/moment.js
         config._pf = {
             empty : false,
             unusedTokens : [],
-            trailingInput : '',
-            skippedInput : [],
+            unusedInput : [],
             overflowMonthOk : false,
-            dstShifted : false,
             overflow : -2,
             charsLeftOver : 0,
             nullInput : false,
             if (parsedInput) {
                 skipped = string.substr(0, string.indexOf(parsedInput));
                 if (skipped.length > 0) {
-                    config._pf.skippedInput.push(skipped);
+                    config._pf.unusedInput.push(skipped);
                 }
                 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
                 totalParsedInputLength += parsedInput.length;
 
         // add remaining unparsed input length to the string
         config._pf.charsLeftOver = stringLength - totalParsedInputLength;
-        config._pf.trailingInput = string;
+        if (string.length > 0) {
+            config._pf.unusedInput.push(string);
+        }
 
         // handle am pm
         if (config._isPm && config._a[HOUR] < 12) {
index 1b716c7087fbf395a958354d790e4c7287369038..4a5d079c67ddaaea7c512fa7f073255c9dfd0154 100644 (file)
@@ -118,27 +118,24 @@ exports.parsing_flags = {
         test.done();
     },
 
-    'trailing output' : function (test) {
-        test.equal(flags('1982-05-25', 'YYYY-MM-DD').trailingInput, '', 'normal input');
-        test.equal(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').trailingInput, ' this is more stuff', 'trailing nonsense');
-        test.equal(flags('1982-05-25 09:30', 'YYYY-MM-DD').trailingInput, ' 09:30', 'trailing legit-looking input');
-        test.equal(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]').trailingInput, '', 'junk that actually gets matched');
+    'unused input' : function (test) {
+        test.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedInput, [], 'normal input');
+        test.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').unusedInput, [' this is more stuff'], 'trailing nonsense');
+        test.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD').unusedInput, [' 09:30'], ['trailing legit-looking input']);
+        test.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]').unusedInput, [], 'junk that actually gets matched');
+        test.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').unusedInput, ['stuff at beginning '], 'leading junk');
+        test.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD').unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
 
         test.done();
     },
 
-    'skipped input' : function (test) {
-        test.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').skippedInput, [], 'normal input');
-        test.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').skippedInput, ['stuff at beginning '], 'leading junk');
-        test.deepEqual(flags('1982 junk 05 more junk25', 'YYYY-MM-DD').skippedInput, [' junk ', ' more junk'], 'interstitial junk');
-
-        test.done();
-    },
-
-    'skipped input strict' : function (test) {
-        test.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').skippedInput, [], 'normal input');
-        test.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').skippedInput, ['stuff at beginning '], 'leading junk');
-        test.deepEqual(flags('1982 junk 05 more junk25', 'YYYY-MM-DD').skippedInput, [' junk ', ' more junk'], 'interstitial junk');
+    'unused input strict' : function (test) {
+        test.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedInput, [], 'normal input');
+        test.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD', true).unusedInput, [' this is more stuff'], 'trailing nonsense');
+        test.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD', true).unusedInput, [' 09:30'], ['trailing legit-looking input']);
+        test.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]', true).unusedInput, [], 'junk that actually gets matched');
+        test.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD', true).unusedInput, ['stuff at beginning '], 'leading junk');
+        test.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD', true).unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
 
         test.done();
     },