--- /dev/null
+import { Duration } from './constructor';
+import { getLocale } from '../locale/locales';
+
+// If passed a locale key, it will return a cloned instance that is set
+// to the specified locale. Otherwise, it will return the name of the
+// locale that is set on this instance.
+export function locale (key) {
+ var clone, newLocaleData;
+
+ if (key === undefined) {
+ return this._locale._abbr;
+ } else {
+ clone = new Duration(this);
+ newLocaleData = getLocale(key);
+ if (newLocaleData != null) {
+ clone._locale = newLocaleData;
+ }
+ return clone;
+ }
+}
+
+export function lang (key) {
+ if (key === undefined) {
+ return this.localeData();
+ } else {
+ return this.locale(key);
+ }
+}
+
+export function localeData () {
+ return this._locale;
+}
import { Duration } from './constructor';
-import wrap from '../utils/wrap';
-
-var proto = Duration.prototype;
-
import { abs } from './abs';
import { add, subtract } from './add-subtract';
import { as, asMilliseconds, asSeconds, asMinutes, asHours, asDays, asWeeks, asMonths, asYears, valueOf } from './as';
import { get, milliseconds, seconds, minutes, hours, days, months, years, weeks } from './get';
import { humanize } from './humanize';
import { toISOString } from './iso-string';
-import { lang, locale, localeData } from '../moment/locale';
+import { lang, locale, localeData } from './locale';
import { isValid } from './valid';
+var proto = Duration.prototype;
proto.isValid = isValid;
proto.abs = abs;
proto.add = add;
proto.toISOString = toISOString;
proto.toString = toISOString;
proto.toJSON = toISOString;
-proto.locale = wrap(Duration, locale, true);
+proto.locale = locale;
proto.localeData = localeData;
// Deprecations
import { deprecate } from '../utils/deprecate';
proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString);
-proto.lang = deprecate('duration.lang() is deprecated. Use locale() or localeData() instead.', wrap(Duration, lang));
+proto.lang = deprecate('duration.lang() is deprecated. Use locale() or localeData() instead.', lang);
+import { Moment } from './constructor';
import { getLocale } from '../locale/locales';
-import { deprecate } from '../utils/deprecate';
-// If passed a locale key, it will set the locale for this
-// instance. Otherwise, it will return the locale configuration
-// variables for this instance.
+// If passed a locale key, it will return a cloned instance that is set
+// to the specified locale. Otherwise, it will return the name of the
+// locale that is set on this instance.
export function locale (key) {
- var newLocaleData;
+ var clone, newLocaleData;
if (key === undefined) {
return this._locale._abbr;
} else {
+ clone = new Moment(this);
newLocaleData = getLocale(key);
if (newLocaleData != null) {
- this._locale = newLocaleData;
+ clone._locale = newLocaleData;
}
- return this;
+ return clone;
}
}
import { Moment } from './constructor';
-import wrap from '../utils/wrap';
-
-var proto = Moment.prototype;
-
import { add, subtract } from './add-subtract';
import { calendar, getCalendarFormat } from './calendar';
import { isBefore, isBetween, isSame, isAfter, isSameOrAfter, isSameOrBefore } from './compare';
import { valueOf, toDate, toArray, toObject, toJSON, unix } from './to-type';
import { isValid, parsingFlags, invalidAt } from './valid';
import { creationData } from './creation-data';
+import wrap from '../utils/wrap';
+var proto = Moment.prototype;
proto.add = wrap(Moment, add);
proto.calendar = calendar;
proto.diff = diff;
proto.isSameOrAfter = isSameOrAfter;
proto.isSameOrBefore = isSameOrBefore;
proto.isValid = isValid;
-proto.locale = wrap(Moment, locale);
+proto.locale = locale;
proto.localeData = localeData;
proto.parsingFlags = parsingFlags;
proto.set = wrap(Moment, stringSet);
wrap(Moment, getSetDayOfMonth, true));
proto.lang = deprecate(
'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
- wrap(Moment, lang));
+ lang);
proto.max = deprecate(
'moment().max() is deprecated. Use moment.min() instead (notice lack of parentheses).',
prototypeMax);