]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Clean up the code a bit
authorMichal Brašna <michal.brasna@gmail.com>
Wed, 13 May 2015 15:29:35 +0000 (17:29 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 12 Jul 2015 23:37:27 +0000 (16:37 -0700)
src/lib/format/format.js
src/lib/locale/formats.js
src/lib/locale/locales.js
src/lib/units/day-of-week.js
src/lib/units/offset.js

index 565da01e29954666aa740c76920b743aa8622b24..51cd0c1328bba4c3afd646490fbd5396dbe99abb 100644 (file)
@@ -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);
 }
index b9d2660cd1bdbc619ab60e7357540c635402084d..6d83b0394843d490250241143afd42937cce57f3 100644 (file)
@@ -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];
 }
index 0e58dedfe2ca6a9c16d40f37d2efb3bd915f4d36..a32e5aced265b215b3042b3694e639950b618418 100644 (file)
@@ -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
index 7af2408376bb0ea6d38975999037b5d6256e3ac2..a0c7a24ce775151b1097166f0a82a3e2951f7fe9 100644 (file)
@@ -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
index 6c3e2e2ab022156ec455c27a165ce8179d577844..c9b692239449edd0e3adbc4d688c5fd9c6c318b5 100644 (file)
@@ -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;
 }