From: Iskren Chernev Date: Tue, 14 Jan 2014 07:04:15 +0000 (-0800) Subject: Refactor _pf handling X-Git-Tag: 2.5.1~5^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48040158030d70e8e9db7e571390809cb137e5a6;p=thirdparty%2Fmoment.git Refactor _pf handling --- diff --git a/moment.js b/moment.js index 87a10cc56..8690dc9b7 100644 --- a/moment.js +++ b/moment.js @@ -278,6 +278,23 @@ 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); @@ -571,21 +588,6 @@ } } - 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()) && @@ -1340,7 +1342,7 @@ 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); @@ -1541,10 +1543,6 @@ var input = config._i, format = config._f; - if (typeof config._pf === 'undefined') { - initializeParsingFlags(config); - } - if (input === null) { return moment.invalid({nullInput: true}); } @@ -1581,7 +1579,8 @@ _f : format, _l : lang, _strict : strict, - _isUTC : false + _isUTC : false, + _pf : defaultParsingFlags() }); }; @@ -1599,7 +1598,8 @@ _l : lang, _i : input, _f : format, - _strict : strict + _strict : strict, + _pf : defaultParsingFlags() }).utc(); return m;