]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Refactor _pf handling
authorIskren Chernev <iskren.chernev@gmail.com>
Tue, 14 Jan 2014 07:04:15 +0000 (23:04 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Tue, 14 Jan 2014 07:16:46 +0000 (23:16 -0800)
moment.js

index 87a10cc56cf1cb976908d0b65c30663dd534e518..8690dc9b72db64bf1019a32ce3cee49ddb811a53 100644 (file)
--- a/moment.js
+++ b/moment.js
 
         lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
 
+    function defaultParsingFlags() {
+        // We need to deep clone this object, and es5 standard is not very
+        // helpful.
+        return {
+            empty : false,
+            unusedTokens : [],
+            unusedInput : [],
+            overflow : -2,
+            charsLeftOver : 0,
+            nullInput : false,
+            invalidMonth : null,
+            invalidFormat : false,
+            userInvalidated : false,
+            iso: false
+        };
+    }
+
     function padToken(func, count) {
         return function (a) {
             return leftZeroFill(func.call(this, a), count);
         }
     }
 
-    function initializeParsingFlags(config) {
-        config._pf = {
-            empty : false,
-            unusedTokens : [],
-            unusedInput : [],
-            overflow : -2,
-            charsLeftOver : 0,
-            nullInput : false,
-            invalidMonth : null,
-            invalidFormat : false,
-            userInvalidated : false,
-            iso: false
-        };
-    }
-
     function isValid(m) {
         if (m._isValid == null) {
             m._isValid = !isNaN(m._d.getTime()) &&
         for (i = 0; i < config._f.length; i++) {
             currentScore = 0;
             tempConfig = extend({}, config);
-            initializeParsingFlags(tempConfig);
+            tempConfig._pf = defaultParsingFlags();
             tempConfig._f = config._f[i];
             makeDateFromStringAndFormat(tempConfig);
 
         var input = config._i,
             format = config._f;
 
-        if (typeof config._pf === 'undefined') {
-            initializeParsingFlags(config);
-        }
-
         if (input === null) {
             return moment.invalid({nullInput: true});
         }
             _f : format,
             _l : lang,
             _strict : strict,
-            _isUTC : false
+            _isUTC : false,
+            _pf : defaultParsingFlags()
         });
     };
 
             _l : lang,
             _i : input,
             _f : format,
-            _strict : strict
+            _strict : strict,
+            _pf : defaultParsingFlags()
         }).utc();
 
         return m;