]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
simplify empty handling 1098/head
authorIsaac Cambron <isaac@isaaccambron.com>
Thu, 26 Sep 2013 16:25:57 +0000 (12:25 -0400)
committerIsaac Cambron <isaac@isaaccambron.com>
Thu, 26 Sep 2013 16:25:57 +0000 (12:25 -0400)
moment.js

index 76db0b2b291696fe23e5f81ec5f58cb48947ab0b..de4f4456636550f765a12c316c30449b49400c4d 100644 (file)
--- a/moment.js
+++ b/moment.js
             if (m._strict) {
                 m._isValid = m._isValid &&
                     m._pf.charsLeftOver === 0 &&
-                    m._pf.unusedTokens.length == 0;
+                    m._pf.unusedTokens.length === 0;
             }
         }
         return m._isValid;
 
     // get the regex to find the next token
     function getParseRegexForToken(token, config) {
+        var a;
         switch (token) {
         case 'DDDD':
             return parseTokenThreeDigits;
         case 's':
             return parseTokenOneOrTwoDigits;
         default :
-            return null;
+            a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
+            return a;
         }
     }
 
-    function getDefaultParserRegex(token) {
-        return new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
-    }
-
     function timezoneMinutesFromString(string) {
         var tzchunk = (parseTokenTimezone.exec(string) || [])[0],
             parts = (tzchunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
 
     // date from string and format string
     function makeDateFromStringAndFormat(config) {
-        config._pf.empty = true;
         config._a = [];
+        config._pf.empty = true;
 
         // This array is used to make a Date, either with `new Date` or `Date.UTC`
         var lang = getLangDefinition(config._l),
             string = '' + config._i,
-            i, parsedInput, tokens, regex, defaulted, token,
+            i, parsedInput, tokens, regex, token,
             stringLength = string.length,
             totalParsedInputLength = 0;
 
 
         for (i = 0; i < tokens.length; i++) {
             token = tokens[i];
-            defaulted = false;
             regex = getParseRegexForToken(token, config);
-            if (regex === null) {
-                regex = getDefaultParserRegex(token);
-                defaulted = true;
-            }
             if (config._strict) {
                 regex = new RegExp("^" + regex.source, regex.ignoreCase ? "i" : "");
             }
             if (parsedInput) {
                 string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
                 totalParsedInputLength += parsedInput.length;
-                if (!defaulted) {
-                    config._pf.empty = false;
-                }
             }
-            else {
-                if (!defaulted) {
-                    config._pf.unusedTokens.push(token);
-                }
-            }
-
-            // don't parse if its not a known token
+            // don't parse if it's not a known token
             if (formatTokenFunctions[token]) {
+                if (parsedInput) {
+                    config._pf.empty = false;
+                }
                 addTimeToArrayFromToken(token, parsedInput, config);
             }
         }