diff options
Diffstat (limited to 'library/moment/src/lib/locale')
-rw-r--r-- | library/moment/src/lib/locale/calendar.js | 13 | ||||
-rw-r--r-- | library/moment/src/lib/locale/constructor.js | 2 | ||||
-rw-r--r-- | library/moment/src/lib/locale/en.js | 15 | ||||
-rw-r--r-- | library/moment/src/lib/locale/formats.js | 23 | ||||
-rw-r--r-- | library/moment/src/lib/locale/invalid.js | 5 | ||||
-rw-r--r-- | library/moment/src/lib/locale/lists.js | 48 | ||||
-rw-r--r-- | library/moment/src/lib/locale/locale.js | 35 | ||||
-rw-r--r-- | library/moment/src/lib/locale/locales.js | 117 | ||||
-rw-r--r-- | library/moment/src/lib/locale/ordinal.js | 7 | ||||
-rw-r--r-- | library/moment/src/lib/locale/pre-post-format.js | 3 | ||||
-rw-r--r-- | library/moment/src/lib/locale/prototype.js | 70 | ||||
-rw-r--r-- | library/moment/src/lib/locale/relative.js | 27 | ||||
-rw-r--r-- | library/moment/src/lib/locale/set.js | 14 |
13 files changed, 379 insertions, 0 deletions
diff --git a/library/moment/src/lib/locale/calendar.js b/library/moment/src/lib/locale/calendar.js new file mode 100644 index 000000000..22545b964 --- /dev/null +++ b/library/moment/src/lib/locale/calendar.js @@ -0,0 +1,13 @@ +export var defaultCalendar = { + sameDay : '[Today at] LT', + nextDay : '[Tomorrow at] LT', + nextWeek : 'dddd [at] LT', + lastDay : '[Yesterday at] LT', + lastWeek : '[Last] dddd [at] LT', + sameElse : 'L' +}; + +export function calendar (key, mom, now) { + var output = this._calendar[key]; + return typeof output === 'function' ? output.call(mom, now) : output; +} diff --git a/library/moment/src/lib/locale/constructor.js b/library/moment/src/lib/locale/constructor.js new file mode 100644 index 000000000..2c17b5d00 --- /dev/null +++ b/library/moment/src/lib/locale/constructor.js @@ -0,0 +1,2 @@ +export function Locale() { +} diff --git a/library/moment/src/lib/locale/en.js b/library/moment/src/lib/locale/en.js new file mode 100644 index 000000000..20964cd9c --- /dev/null +++ b/library/moment/src/lib/locale/en.js @@ -0,0 +1,15 @@ +import './prototype'; +import { getSetGlobalLocale } from './locales'; +import toInt from '../utils/to-int'; + +getSetGlobalLocale('en', { + ordinalParse: /\d{1,2}(th|st|nd|rd)/, + ordinal : function (number) { + var b = number % 10, + output = (toInt(number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + return number + output; + } +}); diff --git a/library/moment/src/lib/locale/formats.js b/library/moment/src/lib/locale/formats.js new file mode 100644 index 000000000..6d83b0394 --- /dev/null +++ b/library/moment/src/lib/locale/formats.js @@ -0,0 +1,23 @@ +export var defaultLongDateFormat = { + LTS : 'h:mm:ss A', + LT : 'h:mm A', + L : 'MM/DD/YYYY', + LL : 'MMMM D, YYYY', + LLL : 'MMMM D, YYYY h:mm A', + LLLL : 'dddd, MMMM D, YYYY h:mm A' +}; + +export function longDateFormat (key) { + var format = this._longDateFormat[key], + formatUpper = this._longDateFormat[key.toUpperCase()]; + + if (format || !formatUpper) { + return format; + } + + this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) { + return val.slice(1); + }); + + return this._longDateFormat[key]; +} diff --git a/library/moment/src/lib/locale/invalid.js b/library/moment/src/lib/locale/invalid.js new file mode 100644 index 000000000..e9096339b --- /dev/null +++ b/library/moment/src/lib/locale/invalid.js @@ -0,0 +1,5 @@ +export var defaultInvalidDate = 'Invalid date'; + +export function invalidDate () { + return this._invalidDate; +} diff --git a/library/moment/src/lib/locale/lists.js b/library/moment/src/lib/locale/lists.js new file mode 100644 index 000000000..ea0161ab9 --- /dev/null +++ b/library/moment/src/lib/locale/lists.js @@ -0,0 +1,48 @@ +import { getLocale } from './locales'; +import { createUTC } from '../create/utc'; + +function get (format, index, field, setter) { + var locale = getLocale(); + var utc = createUTC().set(setter, index); + return locale[field](utc, format); +} + +function list (format, index, field, count, setter) { + if (typeof format === 'number') { + index = format; + format = undefined; + } + + format = format || ''; + + if (index != null) { + return get(format, index, field, setter); + } + + var i; + var out = []; + for (i = 0; i < count; i++) { + out[i] = get(format, i, field, setter); + } + return out; +} + +export function listMonths (format, index) { + return list(format, index, 'months', 12, 'month'); +} + +export function listMonthsShort (format, index) { + return list(format, index, 'monthsShort', 12, 'month'); +} + +export function listWeekdays (format, index) { + return list(format, index, 'weekdays', 7, 'day'); +} + +export function listWeekdaysShort (format, index) { + return list(format, index, 'weekdaysShort', 7, 'day'); +} + +export function listWeekdaysMin (format, index) { + return list(format, index, 'weekdaysMin', 7, 'day'); +} diff --git a/library/moment/src/lib/locale/locale.js b/library/moment/src/lib/locale/locale.js new file mode 100644 index 000000000..2fc3c46ff --- /dev/null +++ b/library/moment/src/lib/locale/locale.js @@ -0,0 +1,35 @@ +// Side effect imports +import './prototype'; + +import { + getSetGlobalLocale, + defineLocale, + getLocale +} from './locales'; + +import { + listMonths, + listMonthsShort, + listWeekdays, + listWeekdaysShort, + listWeekdaysMin +} from './lists'; + +export { + getSetGlobalLocale, + defineLocale, + getLocale, + listMonths, + listMonthsShort, + listWeekdays, + listWeekdaysShort, + listWeekdaysMin +}; + +import { deprecate } from '../utils/deprecate'; +import { hooks } from '../utils/hooks'; + +hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale); +hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale); + +import './en'; diff --git a/library/moment/src/lib/locale/locales.js b/library/moment/src/lib/locale/locales.js new file mode 100644 index 000000000..a32e5aced --- /dev/null +++ b/library/moment/src/lib/locale/locales.js @@ -0,0 +1,117 @@ +import isArray from '../utils/is-array'; +import compareArrays from '../utils/compare-arrays'; +import { Locale } from './constructor'; + +// internal storage for locale config files +var locales = {}; +var globalLocale; + +function normalizeLocale(key) { + return key ? key.toLowerCase().replace('_', '-') : key; +} + +// pick the locale from the array +// try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each +// substring from most specific to least, but move to the next array item if it's a more specific variant than the current root +function chooseLocale(names) { + var i = 0, j, next, locale, split; + + while (i < names.length) { + split = normalizeLocale(names[i]).split('-'); + j = split.length; + next = normalizeLocale(names[i + 1]); + next = next ? next.split('-') : null; + while (j > 0) { + locale = loadLocale(split.slice(0, j).join('-')); + if (locale) { + return locale; + } + if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) { + //the next array item is better than a shallower substring of this one + break; + } + j--; + } + i++; + } + return null; +} + +function loadLocale(name) { + var oldLocale = null; + // TODO: Find a better way to register and load all the locales in Node + if (!locales[name] && typeof module !== 'undefined' && + module && module.exports) { + try { + oldLocale = globalLocale._abbr; + require('./locale/' + name); + // because defineLocale currently also sets the global locale, we + // want to undo that for lazy loaded locales + getSetGlobalLocale(oldLocale); + } catch (e) { } + } + return locales[name]; +} + +// This function will load locale and then set the global locale. If +// no arguments are passed in, it will simply return the current global +// locale key. +export function getSetGlobalLocale (key, values) { + var data; + if (key) { + if (typeof values === 'undefined') { + data = getLocale(key); + } + else { + data = defineLocale(key, values); + } + + if (data) { + // moment.duration._locale = moment._locale = data; + globalLocale = data; + } + } + + return globalLocale._abbr; +} + +export function defineLocale (name, values) { + if (values !== null) { + values.abbr = name; + locales[name] = locales[name] || new Locale(); + locales[name].set(values); + + // backwards compat for now: also set the locale + getSetGlobalLocale(name); + + return locales[name]; + } else { + // useful for testing + delete locales[name]; + return null; + } +} + +// returns locale data +export function getLocale (key) { + var locale; + + if (key && key._locale && key._locale._abbr) { + key = key._locale._abbr; + } + + if (!key) { + return globalLocale; + } + + if (!isArray(key)) { + //short-circuit everything else + locale = loadLocale(key); + if (locale) { + return locale; + } + key = [key]; + } + + return chooseLocale(key); +} diff --git a/library/moment/src/lib/locale/ordinal.js b/library/moment/src/lib/locale/ordinal.js new file mode 100644 index 000000000..0028aca02 --- /dev/null +++ b/library/moment/src/lib/locale/ordinal.js @@ -0,0 +1,7 @@ +export var defaultOrdinal = '%d'; +export var defaultOrdinalParse = /\d{1,2}/; + +export function ordinal (number) { + return this._ordinal.replace('%d', number); +} + diff --git a/library/moment/src/lib/locale/pre-post-format.js b/library/moment/src/lib/locale/pre-post-format.js new file mode 100644 index 000000000..10ed20584 --- /dev/null +++ b/library/moment/src/lib/locale/pre-post-format.js @@ -0,0 +1,3 @@ +export function preParsePostFormat (string) { + return string; +} diff --git a/library/moment/src/lib/locale/prototype.js b/library/moment/src/lib/locale/prototype.js new file mode 100644 index 000000000..ed02d4f3b --- /dev/null +++ b/library/moment/src/lib/locale/prototype.js @@ -0,0 +1,70 @@ +import { Locale } from './constructor'; + +var proto = Locale.prototype; + +import { defaultCalendar, calendar } from './calendar'; +import { defaultLongDateFormat, longDateFormat } from './formats'; +import { defaultInvalidDate, invalidDate } from './invalid'; +import { defaultOrdinal, ordinal, defaultOrdinalParse } from './ordinal'; +import { preParsePostFormat } from './pre-post-format'; +import { defaultRelativeTime, relativeTime, pastFuture } from './relative'; +import { set } from './set'; + +proto._calendar = defaultCalendar; +proto.calendar = calendar; +proto._longDateFormat = defaultLongDateFormat; +proto.longDateFormat = longDateFormat; +proto._invalidDate = defaultInvalidDate; +proto.invalidDate = invalidDate; +proto._ordinal = defaultOrdinal; +proto.ordinal = ordinal; +proto._ordinalParse = defaultOrdinalParse; +proto.preparse = preParsePostFormat; +proto.postformat = preParsePostFormat; +proto._relativeTime = defaultRelativeTime; +proto.relativeTime = relativeTime; +proto.pastFuture = pastFuture; +proto.set = set; + +// Month +import { + localeMonthsParse, + defaultLocaleMonths, localeMonths, + defaultLocaleMonthsShort, localeMonthsShort +} from '../units/month'; + +proto.months = localeMonths; +proto._months = defaultLocaleMonths; +proto.monthsShort = localeMonthsShort; +proto._monthsShort = defaultLocaleMonthsShort; +proto.monthsParse = localeMonthsParse; + +// Week +import { localeWeek, defaultLocaleWeek, localeFirstDayOfYear, localeFirstDayOfWeek } from '../units/week'; +proto.week = localeWeek; +proto._week = defaultLocaleWeek; +proto.firstDayOfYear = localeFirstDayOfYear; +proto.firstDayOfWeek = localeFirstDayOfWeek; + +// Day of Week +import { + localeWeekdaysParse, + defaultLocaleWeekdays, localeWeekdays, + defaultLocaleWeekdaysMin, localeWeekdaysMin, + defaultLocaleWeekdaysShort, localeWeekdaysShort +} from '../units/day-of-week'; + +proto.weekdays = localeWeekdays; +proto._weekdays = defaultLocaleWeekdays; +proto.weekdaysMin = localeWeekdaysMin; +proto._weekdaysMin = defaultLocaleWeekdaysMin; +proto.weekdaysShort = localeWeekdaysShort; +proto._weekdaysShort = defaultLocaleWeekdaysShort; +proto.weekdaysParse = localeWeekdaysParse; + +// Hours +import { localeIsPM, defaultLocaleMeridiemParse, localeMeridiem } from '../units/hour'; + +proto.isPM = localeIsPM; +proto._meridiemParse = defaultLocaleMeridiemParse; +proto.meridiem = localeMeridiem; diff --git a/library/moment/src/lib/locale/relative.js b/library/moment/src/lib/locale/relative.js new file mode 100644 index 000000000..5986a6754 --- /dev/null +++ b/library/moment/src/lib/locale/relative.js @@ -0,0 +1,27 @@ +export var defaultRelativeTime = { + future : 'in %s', + past : '%s ago', + s : 'a few seconds', + m : 'a minute', + mm : '%d minutes', + h : 'an hour', + hh : '%d hours', + d : 'a day', + dd : '%d days', + M : 'a month', + MM : '%d months', + y : 'a year', + yy : '%d years' +}; + +export function relativeTime (number, withoutSuffix, string, isFuture) { + var output = this._relativeTime[string]; + return (typeof output === 'function') ? + output(number, withoutSuffix, string, isFuture) : + output.replace(/%d/i, number); +} + +export function pastFuture (diff, output) { + var format = this._relativeTime[diff > 0 ? 'future' : 'past']; + return typeof format === 'function' ? format(output) : format.replace(/%s/i, output); +} diff --git a/library/moment/src/lib/locale/set.js b/library/moment/src/lib/locale/set.js new file mode 100644 index 000000000..32db2ad79 --- /dev/null +++ b/library/moment/src/lib/locale/set.js @@ -0,0 +1,14 @@ +export function set (config) { + var prop, i; + for (i in config) { + prop = config[i]; + if (typeof prop === 'function') { + this[i] = prop; + } else { + this['_' + i] = prop; + } + } + // Lenient ordinal parsing accepts just a number in addition to + // number + (possibly) stuff coming from _ordinalParseLenient. + this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source); +} |