]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Replace hacks with harder to spot ones
authorIskren Chernev <iskren.chernev@gmail.com>
Thu, 16 Jun 2016 06:34:09 +0000 (23:34 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 20 Jun 2016 08:22:46 +0000 (01:22 -0700)
src/lib/locale/base-config.js
src/lib/locale/locales.js
src/lib/locale/set.js
src/lib/units/day-of-week.js
src/lib/units/month.js
src/test/moment/locale_inheritance.js
src/test/moment/locale_update.js

index 9a6cb1102cb326d416a41f8214f5fb4fbfc78bf5..cbb0b36b49fa971a6827caf3523bd32ea128e562 100644 (file)
@@ -8,8 +8,6 @@ import { defaultRelativeTime } from './relative';
 import {
     defaultLocaleMonths,
     defaultLocaleMonthsShort,
-    defaultMonthsRegex,
-    defaultMonthsShortRegex,
 } from '../units/month';
 
 // week
@@ -20,10 +18,6 @@ import {
     defaultLocaleWeekdays,
     defaultLocaleWeekdaysMin,
     defaultLocaleWeekdaysShort,
-
-    defaultWeekdaysRegex,
-    defaultWeekdaysShortRegex,
-    defaultWeekdaysMinRegex,
 } from '../units/day-of-week';
 
 // meridiem
@@ -39,8 +33,6 @@ export var baseConfig = {
 
     months: defaultLocaleMonths,
     monthsShort: defaultLocaleMonthsShort,
-    monthsRegex: defaultMonthsRegex,
-    monthsShortRegex: defaultMonthsShortRegex,
 
     week: defaultLocaleWeek,
 
@@ -48,9 +40,5 @@ export var baseConfig = {
     weekdaysMin: defaultLocaleWeekdaysMin,
     weekdaysShort: defaultLocaleWeekdaysShort,
 
-    weekdaysRegex: defaultWeekdaysRegex,
-    weekdaysShortRegex: defaultWeekdaysShortRegex,
-    weekdaysMinRegex: defaultWeekdaysMinRegex,
-
     meridiemParse: defaultLocaleMeridiemParse
 };
index 9b3565cfdabcecaf03efdfb892f341ea5657376b..abdafcea7c2be2c181c52f78cb449e7bf50926c7 100644 (file)
@@ -82,16 +82,8 @@ export function getSetGlobalLocale (key, values) {
     return globalLocale._abbr;
 }
 
-function sanitizeLocaleConfig(config) {
-    if (!hasOwnProp(config, 'longDateFormat')) {
-        config.longDateFormat = {};
-    }
-    return config;
-}
-
 export function defineLocale (name, config) {
     if (config !== null) {
-        config = sanitizeLocaleConfig(config);
         var parentConfig = baseConfig;
         config.abbr = name;
         if (locales[name] != null) {
index 1fd1389024fe2fbcfed0ccd507b8e06f01c9a642..45a2f46e12f5b29d644187d32a1d6291d5c5e4b7 100644 (file)
@@ -34,5 +34,13 @@ export function mergeConfigs(parentConfig, childConfig) {
             }
         }
     }
+    for (prop in parentConfig) {
+        if (hasOwnProp(parentConfig, prop) &&
+                !hasOwnProp(childConfig, prop) &&
+                isObject(parentConfig[prop])) {
+            // make sure changes to properties don't modify parent config
+            res[prop] = extend({}, res[prop]);
+        }
+    }
     return res;
 }
index de582255a51f08ae70f47d87a0557446c04993a7..04968c649ba1bef50227376c29baf777f3f06e84 100644 (file)
@@ -257,7 +257,7 @@ export function getSetISODayOfWeek (input) {
     }
 }
 
-export var defaultWeekdaysRegex = matchWord;
+var defaultWeekdaysRegex = matchWord;
 export function weekdaysRegex (isStrict) {
     if (this._weekdaysParseExact) {
         if (!hasOwnProp(this, '_weekdaysRegex')) {
@@ -269,12 +269,15 @@ export function weekdaysRegex (isStrict) {
             return this._weekdaysRegex;
         }
     } else {
+        if (!hasOwnProp(this, '_weekdaysRegex')) {
+            this._weekdaysRegex = defaultWeekdaysRegex;
+        }
         return this._weekdaysStrictRegex && isStrict ?
             this._weekdaysStrictRegex : this._weekdaysRegex;
     }
 }
 
-export var defaultWeekdaysShortRegex = matchWord;
+var defaultWeekdaysShortRegex = matchWord;
 export function weekdaysShortRegex (isStrict) {
     if (this._weekdaysParseExact) {
         if (!hasOwnProp(this, '_weekdaysRegex')) {
@@ -286,16 +289,18 @@ export function weekdaysShortRegex (isStrict) {
             return this._weekdaysShortRegex;
         }
     } else {
+        if (!hasOwnProp(this, '_weekdaysShortRegex')) {
+            this._weekdaysShortRegex = defaultWeekdaysShortRegex;
+        }
         return this._weekdaysShortStrictRegex && isStrict ?
             this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
     }
 }
 
-export var defaultWeekdaysMinRegex = matchWord;
+var defaultWeekdaysMinRegex = matchWord;
 export function weekdaysMinRegex (isStrict) {
     if (this._weekdaysParseExact) {
-        if (!hasOwnProp(this, '_weekdaysRegex') ||
-                this._weekdaysRegex === defaultWeekdaysRegex) {
+        if (!hasOwnProp(this, '_weekdaysRegex')) {
             computeWeekdaysParse.call(this);
         }
         if (isStrict) {
@@ -304,6 +309,9 @@ export function weekdaysMinRegex (isStrict) {
             return this._weekdaysMinRegex;
         }
     } else {
+        if (!hasOwnProp(this, '_weekdaysMinRegex')) {
+            this._weekdaysMinRegex = defaultWeekdaysMinRegex;
+        }
         return this._weekdaysMinStrictRegex && isStrict ?
             this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
     }
@@ -350,3 +358,9 @@ function computeWeekdaysParse () {
     this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
     this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
 }
+
+function setDefaultRegexes () {
+    this._weekdaysRegex = defaultWeekdaysRegex;
+    this._weekdaysShortRegex = defaultWeekdaysShortRegex;
+    this._weekdaysMinRegex = defaultWeekdaysMinRegex;
+}
index 0a3fd95656a20b252b7d84683d9e2ff6a66791a8..57e52bde2041a3d08e4d3ed008ced2b60286eab1 100644 (file)
@@ -199,12 +199,10 @@ export function getDaysInMonth () {
     return daysInMonth(this.year(), this.month());
 }
 
-export var defaultMonthsRegex = matchWord;
-export var defaultMonthsShortRegex = matchWord;
+var defaultMonthsShortRegex = matchWord;
 export function monthsShortRegex (isStrict) {
     if (this._monthsParseExact) {
-        if (!hasOwnProp(this, '_monthsRegex') ||
-                this._monthsRegex === defaultMonthsRegex) {
+        if (!hasOwnProp(this, '_monthsRegex')) {
             computeMonthsParse.call(this);
         }
         if (isStrict) {
@@ -213,15 +211,18 @@ export function monthsShortRegex (isStrict) {
             return this._monthsShortRegex;
         }
     } else {
+        if (!hasOwnProp(this, '_monthsShortRegex')) {
+            this._monthsShortRegex = defaultMonthsShortRegex;
+        }
         return this._monthsShortStrictRegex && isStrict ?
             this._monthsShortStrictRegex : this._monthsShortRegex;
     }
 }
 
+var defaultMonthsRegex = matchWord;
 export function monthsRegex (isStrict) {
     if (this._monthsParseExact) {
-        if (!hasOwnProp(this, '_monthsRegex') ||
-                this._monthsRegex === defaultMonthsRegex) {
+        if (!hasOwnProp(this, '_monthsRegex')) {
             computeMonthsParse.call(this);
         }
         if (isStrict) {
@@ -230,6 +231,9 @@ export function monthsRegex (isStrict) {
             return this._monthsRegex;
         }
     } else {
+        if (!hasOwnProp(this, '_monthsRegex')) {
+            this._monthsRegex = defaultMonthsRegex;
+        }
         return this._monthsStrictRegex && isStrict ?
             this._monthsStrictRegex : this._monthsRegex;
     }
index 2fec56e28c18510022520b9d929a892dc64dd16e..f0cb21fdde453bbcfac49be5b21637cdc9476f65 100644 (file)
@@ -142,15 +142,15 @@ test('ordinal parse', function (assert) {
 
     assert.ok(moment.utc('2015-01-1y', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child');
 
-    // moment.defineLocale('base-ordinal-parse-2', {
-    //     ordinalParse : /\d{1,2}x/
-    // });
-    // moment.defineLocale('child-ordinal-parse-2', {
-    //     parentLocale: 'base-ordinal-parse-2',
-    //     ordinalParse : null
-    // });
-
-    // assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
+    moment.defineLocale('base-ordinal-parse-2', {
+        ordinalParse : /\d{1,2}x/
+    });
+    moment.defineLocale('child-ordinal-parse-2', {
+        parentLocale: 'base-ordinal-parse-2',
+        ordinalParse : /\d{1,2}/
+    });
+
+    assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
 });
 
 test('months', function (assert) {
index 4008de2c03487654aef0157fc6a807898318e305..fd189aad1bf15b58a3b689549de7405b62210b0e 100644 (file)
@@ -142,15 +142,15 @@ test('ordinal parse', function (assert) {
 
     assert.ok(moment.utc('2015-01-1y', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child');
 
-    // moment.defineLocale('ordinal-parse-2', null);
-    // moment.defineLocale('ordinal-parse-2', {
-    //     ordinalParse : /\d{1,2}x/
-    // });
-    // moment.updateLocale('ordinal-parse-2', {
-    //     ordinalParse : null
-    // });
-
-    // assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
+    moment.defineLocale('ordinal-parse-2', null);
+    moment.defineLocale('ordinal-parse-2', {
+        ordinalParse : /\d{1,2}x/
+    });
+    moment.updateLocale('ordinal-parse-2', {
+        ordinalParse : /\d{1,2}/
+    });
+
+    assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
 });
 
 test('months', function (assert) {