import {
defaultLocaleMonths,
defaultLocaleMonthsShort,
- defaultMonthsRegex,
- defaultMonthsShortRegex,
} from '../units/month';
// week
defaultLocaleWeekdays,
defaultLocaleWeekdaysMin,
defaultLocaleWeekdaysShort,
-
- defaultWeekdaysRegex,
- defaultWeekdaysShortRegex,
- defaultWeekdaysMinRegex,
} from '../units/day-of-week';
// meridiem
months: defaultLocaleMonths,
monthsShort: defaultLocaleMonthsShort,
- monthsRegex: defaultMonthsRegex,
- monthsShortRegex: defaultMonthsShortRegex,
week: defaultLocaleWeek,
weekdaysMin: defaultLocaleWeekdaysMin,
weekdaysShort: defaultLocaleWeekdaysShort,
- weekdaysRegex: defaultWeekdaysRegex,
- weekdaysShortRegex: defaultWeekdaysShortRegex,
- weekdaysMinRegex: defaultWeekdaysMinRegex,
-
meridiemParse: defaultLocaleMeridiemParse
};
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) {
}
}
}
+ 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;
}
}
}
-export var defaultWeekdaysRegex = matchWord;
+var defaultWeekdaysRegex = matchWord;
export function weekdaysRegex (isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
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')) {
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) {
return this._weekdaysMinRegex;
}
} else {
+ if (!hasOwnProp(this, '_weekdaysMinRegex')) {
+ this._weekdaysMinRegex = defaultWeekdaysMinRegex;
+ }
return this._weekdaysMinStrictRegex && isStrict ?
this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
}
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;
+}
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) {
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) {
return this._monthsRegex;
}
} else {
+ if (!hasOwnProp(this, '_monthsRegex')) {
+ this._monthsRegex = defaultMonthsRegex;
+ }
return this._monthsStrictRegex && isStrict ?
this._monthsStrictRegex : this._monthsRegex;
}
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) {
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) {