From: Michal Brašna Date: Wed, 13 May 2015 15:29:35 +0000 (+0200) Subject: Clean up the code a bit X-Git-Tag: 2.10.5~34^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d2253d4831704ee72f78db73573a44d44604ea5;p=thirdparty%2Fmoment.git Clean up the code a bit --- diff --git a/src/lib/format/format.js b/src/lib/format/format.js index 565da01e2..51cd0c132 100644 --- a/src/lib/format/format.js +++ b/src/lib/format/format.js @@ -68,10 +68,7 @@ export function formatMoment(m, format) { } format = expandFormat(format, m.localeData()); - - if (!formatFunctions[format]) { - formatFunctions[format] = makeFormatFunction(format); - } + formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format); return formatFunctions[format](m); } diff --git a/src/lib/locale/formats.js b/src/lib/locale/formats.js index b9d2660cd..6d83b0394 100644 --- a/src/lib/locale/formats.js +++ b/src/lib/locale/formats.js @@ -8,12 +8,16 @@ export var defaultLongDateFormat = { }; export function longDateFormat (key) { - var output = this._longDateFormat[key]; - if (!output && this._longDateFormat[key.toUpperCase()]) { - output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) { - return val.slice(1); - }); - this._longDateFormat[key] = output; + var format = this._longDateFormat[key], + formatUpper = this._longDateFormat[key.toUpperCase()]; + + if (format || !formatUpper) { + return format; } - return output; + + this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) { + return val.slice(1); + }); + + return this._longDateFormat[key]; } diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index 0e58dedfe..a32e5aced 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -78,9 +78,7 @@ export function getSetGlobalLocale (key, values) { export function defineLocale (name, values) { if (values !== null) { values.abbr = name; - if (!locales[name]) { - locales[name] = new Locale(); - } + locales[name] = locales[name] || new Locale(); locales[name].set(values); // backwards compat for now: also set the locale diff --git a/src/lib/units/day-of-week.js b/src/lib/units/day-of-week.js index 7af240837..a0c7a24ce 100644 --- a/src/lib/units/day-of-week.js +++ b/src/lib/units/day-of-week.js @@ -91,9 +91,7 @@ export function localeWeekdaysMin (m) { export function localeWeekdaysParse (weekdayName) { var i, mom, regex; - if (!this._weekdaysParse) { - this._weekdaysParse = []; - } + this._weekdaysParse = this._weekdaysParse || []; for (i = 0; i < 7; i++) { // make the regex if we don't have it already diff --git a/src/lib/units/offset.js b/src/lib/units/offset.js index 6c3e2e2ab..c9b692239 100644 --- a/src/lib/units/offset.js +++ b/src/lib/units/offset.js @@ -166,12 +166,7 @@ export function setOffsetToParsedOffset () { } export function hasAlignedHourOffset (input) { - if (!input) { - input = 0; - } - else { - input = createLocal(input).utcOffset(); - } + input = input ? createLocal(input).utcOffset() : 0; return (this.utcOffset() - input) % 60 === 0; }