aboutsummaryrefslogtreecommitdiffstats
path: root/resources/lib/moment/moment.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/lib/moment/moment.js')
-rw-r--r--resources/lib/moment/moment.js916
1 files changed, 467 insertions, 449 deletions
diff --git a/resources/lib/moment/moment.js b/resources/lib/moment/moment.js
index 0c0071d5c72b..480b9fb3db59 100644
--- a/resources/lib/moment/moment.js
+++ b/resources/lib/moment/moment.js
@@ -1,5 +1,5 @@
//! moment.js
-//! version : 2.25.2
+//! version : 2.30.1
//! authors : Tim Wood, Iskren Chernev, Moment.js contributors
//! license : MIT
//! momentjs.com
@@ -76,8 +76,9 @@
function map(arr, fn) {
var res = [],
- i;
- for (i = 0; i < arr.length; ++i) {
+ i,
+ arrLen = arr.length;
+ for (i = 0; i < arrLen; ++i) {
res.push(fn(arr[i], i));
}
return res;
@@ -154,24 +155,25 @@
}
function isValid(m) {
- if (m._isValid == null) {
- var flags = getParsingFlags(m),
- parsedParts = some.call(flags.parsedDateParts, function (i) {
- return i != null;
- }),
- isNowValid =
- !isNaN(m._d.getTime()) &&
- flags.overflow < 0 &&
- !flags.empty &&
- !flags.invalidEra &&
- !flags.invalidMonth &&
- !flags.invalidWeekday &&
- !flags.weekdayMismatch &&
- !flags.nullInput &&
- !flags.invalidFormat &&
- !flags.userInvalidated &&
- (!flags.meridiem || (flags.meridiem && parsedParts));
-
+ var flags = null,
+ parsedParts = false,
+ isNowValid = m._d && !isNaN(m._d.getTime());
+ if (isNowValid) {
+ flags = getParsingFlags(m);
+ parsedParts = some.call(flags.parsedDateParts, function (i) {
+ return i != null;
+ });
+ isNowValid =
+ flags.overflow < 0 &&
+ !flags.empty &&
+ !flags.invalidEra &&
+ !flags.invalidMonth &&
+ !flags.invalidWeekday &&
+ !flags.weekdayMismatch &&
+ !flags.nullInput &&
+ !flags.invalidFormat &&
+ !flags.userInvalidated &&
+ (!flags.meridiem || (flags.meridiem && parsedParts));
if (m._strict) {
isNowValid =
isNowValid &&
@@ -179,12 +181,11 @@
flags.unusedTokens.length === 0 &&
flags.bigHour === undefined;
}
-
- if (Object.isFrozen == null || !Object.isFrozen(m)) {
- m._isValid = isNowValid;
- } else {
- return isNowValid;
- }
+ }
+ if (Object.isFrozen == null || !Object.isFrozen(m)) {
+ m._isValid = isNowValid;
+ } else {
+ return isNowValid;
}
return m._isValid;
}
@@ -206,7 +207,10 @@
updateInProgress = false;
function copyConfig(to, from) {
- var i, prop, val;
+ var i,
+ prop,
+ val,
+ momentPropertiesLen = momentProperties.length;
if (!isUndefined(from._isAMomentObject)) {
to._isAMomentObject = from._isAMomentObject;
@@ -239,8 +243,8 @@
to._locale = from._locale;
}
- if (momentProperties.length > 0) {
- for (i = 0; i < momentProperties.length; i++) {
+ if (momentPropertiesLen > 0) {
+ for (i = 0; i < momentPropertiesLen; i++) {
prop = momentProperties[i];
val = from[prop];
if (!isUndefined(val)) {
@@ -295,8 +299,9 @@
var args = [],
arg,
i,
- key;
- for (i = 0; i < arguments.length; i++) {
+ key,
+ argLen = arguments.length;
+ for (i = 0; i < argLen; i++) {
arg = '';
if (typeof arguments[i] === 'object') {
arg += '\n[' + i + '] ';
@@ -446,7 +451,8 @@
);
}
- var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
+ var formattingTokens =
+ /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
formatFunctions = {},
formatTokenFunctions = {};
@@ -624,12 +630,56 @@
return isFunction(format) ? format(output) : format.replace(/%s/i, output);
}
- var aliases = {};
-
- function addUnitAlias(unit, shorthand) {
- var lowerCase = unit.toLowerCase();
- aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
- }
+ var aliases = {
+ D: 'date',
+ dates: 'date',
+ date: 'date',
+ d: 'day',
+ days: 'day',
+ day: 'day',
+ e: 'weekday',
+ weekdays: 'weekday',
+ weekday: 'weekday',
+ E: 'isoWeekday',
+ isoweekdays: 'isoWeekday',
+ isoweekday: 'isoWeekday',
+ DDD: 'dayOfYear',
+ dayofyears: 'dayOfYear',
+ dayofyear: 'dayOfYear',
+ h: 'hour',
+ hours: 'hour',
+ hour: 'hour',
+ ms: 'millisecond',
+ milliseconds: 'millisecond',
+ millisecond: 'millisecond',
+ m: 'minute',
+ minutes: 'minute',
+ minute: 'minute',
+ M: 'month',
+ months: 'month',
+ month: 'month',
+ Q: 'quarter',
+ quarters: 'quarter',
+ quarter: 'quarter',
+ s: 'second',
+ seconds: 'second',
+ second: 'second',
+ gg: 'weekYear',
+ weekyears: 'weekYear',
+ weekyear: 'weekYear',
+ GG: 'isoWeekYear',
+ isoweekyears: 'isoWeekYear',
+ isoweekyear: 'isoWeekYear',
+ w: 'week',
+ weeks: 'week',
+ week: 'week',
+ W: 'isoWeek',
+ isoweeks: 'isoWeek',
+ isoweek: 'isoWeek',
+ y: 'year',
+ years: 'year',
+ year: 'year',
+ };
function normalizeUnits(units) {
return typeof units === 'string'
@@ -654,11 +704,24 @@
return normalizedInput;
}
- var priorities = {};
-
- function addUnitPriority(unit, priority) {
- priorities[unit] = priority;
- }
+ var priorities = {
+ date: 9,
+ day: 11,
+ weekday: 11,
+ isoWeekday: 11,
+ dayOfYear: 4,
+ hour: 13,
+ millisecond: 16,
+ minute: 14,
+ month: 8,
+ quarter: 7,
+ second: 15,
+ weekYear: 1,
+ isoWeekYear: 1,
+ week: 5,
+ isoWeek: 5,
+ year: 1,
+ };
function getPrioritizedUnits(unitsObj) {
var units = [],
@@ -674,95 +737,6 @@
return units;
}
- function isLeapYear(year) {
- return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
- }
-
- function absFloor(number) {
- if (number < 0) {
- // -0 -> 0
- return Math.ceil(number) || 0;
- } else {
- return Math.floor(number);
- }
- }
-
- function toInt(argumentForCoercion) {
- var coercedNumber = +argumentForCoercion,
- value = 0;
-
- if (coercedNumber !== 0 && isFinite(coercedNumber)) {
- value = absFloor(coercedNumber);
- }
-
- return value;
- }
-
- function makeGetSet(unit, keepTime) {
- return function (value) {
- if (value != null) {
- set$1(this, unit, value);
- hooks.updateOffset(this, keepTime);
- return this;
- } else {
- return get(this, unit);
- }
- };
- }
-
- function get(mom, unit) {
- return mom.isValid()
- ? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]()
- : NaN;
- }
-
- function set$1(mom, unit, value) {
- if (mom.isValid() && !isNaN(value)) {
- if (
- unit === 'FullYear' &&
- isLeapYear(mom.year()) &&
- mom.month() === 1 &&
- mom.date() === 29
- ) {
- value = toInt(value);
- mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](
- value,
- mom.month(),
- daysInMonth(value, mom.month())
- );
- } else {
- mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
- }
- }
- }
-
- // MOMENTS
-
- function stringGet(units) {
- units = normalizeUnits(units);
- if (isFunction(this[units])) {
- return this[units]();
- }
- return this;
- }
-
- function stringSet(units, value) {
- if (typeof units === 'object') {
- units = normalizeObjectUnits(units);
- var prioritized = getPrioritizedUnits(units),
- i;
- for (i = 0; i < prioritized.length; i++) {
- this[prioritized[i].unit](units[prioritized[i].unit]);
- }
- } else {
- units = normalizeUnits(units);
- if (isFunction(this[units])) {
- return this[units](value);
- }
- }
- return this;
- }
-
var match1 = /\d/, // 0 - 9
match2 = /\d\d/, // 00 - 99
match3 = /\d{3}/, // 000 - 999
@@ -781,7 +755,10 @@
matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
// any word (or two) characters or numbers including two/three word month in arabic.
// includes scottish gaelic two word and hyphenated months
- matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
+ matchWord =
+ /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
+ match1to2NoLeadingZero = /^[1-9]\d?/, // 1-99
+ match1to2HasZero = /^([1-9]\d|\d)/, // 0-99
regexes;
regexes = {};
@@ -807,15 +784,12 @@
return regexEscape(
s
.replace('\\', '')
- .replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (
- matched,
- p1,
- p2,
- p3,
- p4
- ) {
- return p1 || p2 || p3 || p4;
- })
+ .replace(
+ /\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,
+ function (matched, p1, p2, p3, p4) {
+ return p1 || p2 || p3 || p4;
+ }
+ )
);
}
@@ -823,11 +797,32 @@
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
+ function absFloor(number) {
+ if (number < 0) {
+ // -0 -> 0
+ return Math.ceil(number) || 0;
+ } else {
+ return Math.floor(number);
+ }
+ }
+
+ function toInt(argumentForCoercion) {
+ var coercedNumber = +argumentForCoercion,
+ value = 0;
+
+ if (coercedNumber !== 0 && isFinite(coercedNumber)) {
+ value = absFloor(coercedNumber);
+ }
+
+ return value;
+ }
+
var tokens = {};
function addParseToken(token, callback) {
var i,
- func = callback;
+ func = callback,
+ tokenLen;
if (typeof token === 'string') {
token = [token];
}
@@ -836,7 +831,8 @@
array[callback] = toInt(input);
};
}
- for (i = 0; i < token.length; i++) {
+ tokenLen = token.length;
+ for (i = 0; i < tokenLen; i++) {
tokens[token[i]] = func;
}
}
@@ -854,6 +850,10 @@
}
}
+ function isLeapYear(year) {
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
+ }
+
var YEAR = 0,
MONTH = 1,
DATE = 2,
@@ -864,6 +864,173 @@
WEEK = 7,
WEEKDAY = 8;
+ // FORMATTING
+
+ addFormatToken('Y', 0, 0, function () {
+ var y = this.year();
+ return y <= 9999 ? zeroFill(y, 4) : '+' + y;
+ });
+
+ addFormatToken(0, ['YY', 2], 0, function () {
+ return this.year() % 100;
+ });
+
+ addFormatToken(0, ['YYYY', 4], 0, 'year');
+ addFormatToken(0, ['YYYYY', 5], 0, 'year');
+ addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
+
+ // PARSING
+
+ addRegexToken('Y', matchSigned);
+ addRegexToken('YY', match1to2, match2);
+ addRegexToken('YYYY', match1to4, match4);
+ addRegexToken('YYYYY', match1to6, match6);
+ addRegexToken('YYYYYY', match1to6, match6);
+
+ addParseToken(['YYYYY', 'YYYYYY'], YEAR);
+ addParseToken('YYYY', function (input, array) {
+ array[YEAR] =
+ input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
+ });
+ addParseToken('YY', function (input, array) {
+ array[YEAR] = hooks.parseTwoDigitYear(input);
+ });
+ addParseToken('Y', function (input, array) {
+ array[YEAR] = parseInt(input, 10);
+ });
+
+ // HELPERS
+
+ function daysInYear(year) {
+ return isLeapYear(year) ? 366 : 365;
+ }
+
+ // HOOKS
+
+ hooks.parseTwoDigitYear = function (input) {
+ return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
+ };
+
+ // MOMENTS
+
+ var getSetYear = makeGetSet('FullYear', true);
+
+ function getIsLeapYear() {
+ return isLeapYear(this.year());
+ }
+
+ function makeGetSet(unit, keepTime) {
+ return function (value) {
+ if (value != null) {
+ set$1(this, unit, value);
+ hooks.updateOffset(this, keepTime);
+ return this;
+ } else {
+ return get(this, unit);
+ }
+ };
+ }
+
+ function get(mom, unit) {
+ if (!mom.isValid()) {
+ return NaN;
+ }
+
+ var d = mom._d,
+ isUTC = mom._isUTC;
+
+ switch (unit) {
+ case 'Milliseconds':
+ return isUTC ? d.getUTCMilliseconds() : d.getMilliseconds();
+ case 'Seconds':
+ return isUTC ? d.getUTCSeconds() : d.getSeconds();
+ case 'Minutes':
+ return isUTC ? d.getUTCMinutes() : d.getMinutes();
+ case 'Hours':
+ return isUTC ? d.getUTCHours() : d.getHours();
+ case 'Date':
+ return isUTC ? d.getUTCDate() : d.getDate();
+ case 'Day':
+ return isUTC ? d.getUTCDay() : d.getDay();
+ case 'Month':
+ return isUTC ? d.getUTCMonth() : d.getMonth();
+ case 'FullYear':
+ return isUTC ? d.getUTCFullYear() : d.getFullYear();
+ default:
+ return NaN; // Just in case
+ }
+ }
+
+ function set$1(mom, unit, value) {
+ var d, isUTC, year, month, date;
+
+ if (!mom.isValid() || isNaN(value)) {
+ return;
+ }
+
+ d = mom._d;
+ isUTC = mom._isUTC;
+
+ switch (unit) {
+ case 'Milliseconds':
+ return void (isUTC
+ ? d.setUTCMilliseconds(value)
+ : d.setMilliseconds(value));
+ case 'Seconds':
+ return void (isUTC ? d.setUTCSeconds(value) : d.setSeconds(value));
+ case 'Minutes':
+ return void (isUTC ? d.setUTCMinutes(value) : d.setMinutes(value));
+ case 'Hours':
+ return void (isUTC ? d.setUTCHours(value) : d.setHours(value));
+ case 'Date':
+ return void (isUTC ? d.setUTCDate(value) : d.setDate(value));
+ // case 'Day': // Not real
+ // return void (isUTC ? d.setUTCDay(value) : d.setDay(value));
+ // case 'Month': // Not used because we need to pass two variables
+ // return void (isUTC ? d.setUTCMonth(value) : d.setMonth(value));
+ case 'FullYear':
+ break; // See below ...
+ default:
+ return; // Just in case
+ }
+
+ year = value;
+ month = mom.month();
+ date = mom.date();
+ date = date === 29 && month === 1 && !isLeapYear(year) ? 28 : date;
+ void (isUTC
+ ? d.setUTCFullYear(year, month, date)
+ : d.setFullYear(year, month, date));
+ }
+
+ // MOMENTS
+
+ function stringGet(units) {
+ units = normalizeUnits(units);
+ if (isFunction(this[units])) {
+ return this[units]();
+ }
+ return this;
+ }
+
+ function stringSet(units, value) {
+ if (typeof units === 'object') {
+ units = normalizeObjectUnits(units);
+ var prioritized = getPrioritizedUnits(units),
+ i,
+ prioritizedLen = prioritized.length;
+ for (i = 0; i < prioritizedLen; i++) {
+ this[prioritized[i].unit](units[prioritized[i].unit]);
+ }
+ } else {
+ units = normalizeUnits(units);
+ if (isFunction(this[units])) {
+ return this[units](value);
+ }
+ }
+ return this;
+ }
+
function mod(n, x) {
return ((n % x) + x) % x;
}
@@ -912,17 +1079,9 @@
return this.localeData().months(this, format);
});
- // ALIASES
-
- addUnitAlias('month', 'M');
-
- // PRIORITY
-
- addUnitPriority('month', 8);
-
// PARSING
- addRegexToken('M', match1to2);
+ addRegexToken('M', match1to2, match1to2NoLeadingZero);
addRegexToken('MM', match1to2, match2);
addRegexToken('MMM', function (isStrict, locale) {
return locale.monthsShortRegex(isStrict);
@@ -947,12 +1106,12 @@
// LOCALES
- var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
- '_'
- ),
- defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split(
- '_'
- ),
+ var defaultLocaleMonths =
+ 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
+ '_'
+ ),
+ defaultLocaleMonthsShort =
+ 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),
MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
defaultMonthsShortRegex = matchWord,
defaultMonthsRegex = matchWord;
@@ -1088,8 +1247,6 @@
// MOMENTS
function setMonth(mom, value) {
- var dayOfMonth;
-
if (!mom.isValid()) {
// No op
return mom;
@@ -1107,8 +1264,13 @@
}
}
- dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
- mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
+ var month = value,
+ date = mom.date();
+
+ date = date < 29 ? date : Math.min(date, daysInMonth(mom.year(), month));
+ void (mom._isUTC
+ ? mom._d.setUTCMonth(month, date)
+ : mom._d.setMonth(month, date));
return mom;
}
@@ -1175,27 +1337,24 @@
longPieces = [],
mixedPieces = [],
i,
- mom;
+ mom,
+ shortP,
+ longP;
for (i = 0; i < 12; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, i]);
- shortPieces.push(this.monthsShort(mom, ''));
- longPieces.push(this.months(mom, ''));
- mixedPieces.push(this.months(mom, ''));
- mixedPieces.push(this.monthsShort(mom, ''));
+ shortP = regexEscape(this.monthsShort(mom, ''));
+ longP = regexEscape(this.months(mom, ''));
+ shortPieces.push(shortP);
+ longPieces.push(longP);
+ mixedPieces.push(longP);
+ mixedPieces.push(shortP);
}
// Sorting makes sure if one month (or abbr) is a prefix of another it
// will match the longer piece.
shortPieces.sort(cmpLenRev);
longPieces.sort(cmpLenRev);
mixedPieces.sort(cmpLenRev);
- for (i = 0; i < 12; i++) {
- shortPieces[i] = regexEscape(shortPieces[i]);
- longPieces[i] = regexEscape(longPieces[i]);
- }
- for (i = 0; i < 24; i++) {
- mixedPieces[i] = regexEscape(mixedPieces[i]);
- }
this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._monthsShortRegex = this._monthsRegex;
@@ -1209,69 +1368,6 @@
);
}
- // FORMATTING
-
- addFormatToken('Y', 0, 0, function () {
- var y = this.year();
- return y <= 9999 ? zeroFill(y, 4) : '+' + y;
- });
-
- addFormatToken(0, ['YY', 2], 0, function () {
- return this.year() % 100;
- });
-
- addFormatToken(0, ['YYYY', 4], 0, 'year');
- addFormatToken(0, ['YYYYY', 5], 0, 'year');
- addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
-
- // ALIASES
-
- addUnitAlias('year', 'y');
-
- // PRIORITIES
-
- addUnitPriority('year', 1);
-
- // PARSING
-
- addRegexToken('Y', matchSigned);
- addRegexToken('YY', match1to2, match2);
- addRegexToken('YYYY', match1to4, match4);
- addRegexToken('YYYYY', match1to6, match6);
- addRegexToken('YYYYYY', match1to6, match6);
-
- addParseToken(['YYYYY', 'YYYYYY'], YEAR);
- addParseToken('YYYY', function (input, array) {
- array[YEAR] =
- input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
- });
- addParseToken('YY', function (input, array) {
- array[YEAR] = hooks.parseTwoDigitYear(input);
- });
- addParseToken('Y', function (input, array) {
- array[YEAR] = parseInt(input, 10);
- });
-
- // HELPERS
-
- function daysInYear(year) {
- return isLeapYear(year) ? 366 : 365;
- }
-
- // HOOKS
-
- hooks.parseTwoDigitYear = function (input) {
- return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
- };
-
- // MOMENTS
-
- var getSetYear = makeGetSet('FullYear', true);
-
- function getIsLeapYear() {
- return isLeapYear(this.year());
- }
-
function createDate(y, m, d, h, M, s, ms) {
// can't just apply() to create a date:
// https://stackoverflow.com/q/181348
@@ -1377,31 +1473,19 @@
addFormatToken('w', ['ww', 2], 'wo', 'week');
addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
- // ALIASES
-
- addUnitAlias('week', 'w');
- addUnitAlias('isoWeek', 'W');
-
- // PRIORITIES
-
- addUnitPriority('week', 5);
- addUnitPriority('isoWeek', 5);
-
// PARSING
- addRegexToken('w', match1to2);
+ addRegexToken('w', match1to2, match1to2NoLeadingZero);
addRegexToken('ww', match1to2, match2);
- addRegexToken('W', match1to2);
+ addRegexToken('W', match1to2, match1to2NoLeadingZero);
addRegexToken('WW', match1to2, match2);
- addWeekParseToken(['w', 'ww', 'W', 'WW'], function (
- input,
- week,
- config,
- token
- ) {
- week[token.substr(0, 1)] = toInt(input);
- });
+ addWeekParseToken(
+ ['w', 'ww', 'W', 'WW'],
+ function (input, week, config, token) {
+ week[token.substr(0, 1)] = toInt(input);
+ }
+ );
// HELPERS
@@ -1455,17 +1539,6 @@
addFormatToken('e', 0, 0, 'weekday');
addFormatToken('E', 0, 0, 'isoWeekday');
- // ALIASES
-
- addUnitAlias('day', 'd');
- addUnitAlias('weekday', 'e');
- addUnitAlias('isoWeekday', 'E');
-
- // PRIORITY
- addUnitPriority('day', 11);
- addUnitPriority('weekday', 11);
- addUnitPriority('isoWeekday', 11);
-
// PARSING
addRegexToken('d', match1to2);
@@ -1526,9 +1599,8 @@
return ws.slice(n, 7).concat(ws.slice(0, n));
}
- var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split(
- '_'
- ),
+ var defaultLocaleWeekdays =
+ 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
defaultWeekdaysRegex = matchWord,
@@ -1546,24 +1618,24 @@
return m === true
? shiftWeekdays(weekdays, this._week.dow)
: m
- ? weekdays[m.day()]
- : weekdays;
+ ? weekdays[m.day()]
+ : weekdays;
}
function localeWeekdaysShort(m) {
return m === true
? shiftWeekdays(this._weekdaysShort, this._week.dow)
: m
- ? this._weekdaysShort[m.day()]
- : this._weekdaysShort;
+ ? this._weekdaysShort[m.day()]
+ : this._weekdaysShort;
}
function localeWeekdaysMin(m) {
return m === true
? shiftWeekdays(this._weekdaysMin, this._week.dow)
: m
- ? this._weekdaysMin[m.day()]
- : this._weekdaysMin;
+ ? this._weekdaysMin[m.day()]
+ : this._weekdaysMin;
}
function handleStrictParse$1(weekdayName, format, strict) {
@@ -1712,7 +1784,8 @@
if (!this.isValid()) {
return input != null ? this : NaN;
}
- var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
+
+ var day = get(this, 'Day');
if (input != null) {
input = parseWeekday(input, this.localeData());
return this.add(input - day, 'd');
@@ -1911,13 +1984,6 @@
meridiem('a', true);
meridiem('A', false);
- // ALIASES
-
- addUnitAlias('hour', 'h');
-
- // PRIORITY
- addUnitPriority('hour', 13);
-
// PARSING
function matchMeridiem(isStrict, locale) {
@@ -1926,9 +1992,9 @@
addRegexToken('a', matchMeridiem);
addRegexToken('A', matchMeridiem);
- addRegexToken('H', match1to2);
- addRegexToken('h', match1to2);
- addRegexToken('k', match1to2);
+ addRegexToken('H', match1to2, match1to2HasZero);
+ addRegexToken('h', match1to2, match1to2NoLeadingZero);
+ addRegexToken('k', match1to2, match1to2NoLeadingZero);
addRegexToken('HH', match1to2, match2);
addRegexToken('hh', match1to2, match2);
addRegexToken('kk', match1to2, match2);
@@ -2076,6 +2142,12 @@
return globalLocale;
}
+ function isLocaleNameSane(name) {
+ // Prevent names that look like filesystem paths, i.e contain '/' or '\'
+ // Ensure name is available and function returns boolean
+ return !!(name && name.match('^[^/\\\\]*$'));
+ }
+
function loadLocale(name) {
var oldLocale = null,
aliasedRequire;
@@ -2084,7 +2156,8 @@
locales[name] === undefined &&
typeof module !== 'undefined' &&
module &&
- module.exports
+ module.exports &&
+ isLocaleNameSane(name)
) {
try {
oldLocale = globalLocale._abbr;
@@ -2264,21 +2337,21 @@
a[MONTH] < 0 || a[MONTH] > 11
? MONTH
: a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
- ? DATE
- : a[HOUR] < 0 ||
- a[HOUR] > 24 ||
- (a[HOUR] === 24 &&
- (a[MINUTE] !== 0 ||
- a[SECOND] !== 0 ||
- a[MILLISECOND] !== 0))
- ? HOUR
- : a[MINUTE] < 0 || a[MINUTE] > 59
- ? MINUTE
- : a[SECOND] < 0 || a[SECOND] > 59
- ? SECOND
- : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
- ? MILLISECOND
- : -1;
+ ? DATE
+ : a[HOUR] < 0 ||
+ a[HOUR] > 24 ||
+ (a[HOUR] === 24 &&
+ (a[MINUTE] !== 0 ||
+ a[SECOND] !== 0 ||
+ a[MILLISECOND] !== 0))
+ ? HOUR
+ : a[MINUTE] < 0 || a[MINUTE] > 59
+ ? MINUTE
+ : a[SECOND] < 0 || a[SECOND] > 59
+ ? SECOND
+ : a[MILLISECOND] < 0 || a[MILLISECOND] > 999
+ ? MILLISECOND
+ : -1;
if (
getParsingFlags(m)._overflowDayOfYear &&
@@ -2301,8 +2374,10 @@
// iso 8601 regex
// 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
- var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
- basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
+ var extendedIsoRegex =
+ /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
+ basicIsoRegex =
+ /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
isoDates = [
['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
@@ -2333,7 +2408,8 @@
],
aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
// RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
- rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
+ rfc2822 =
+ /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
obsOffsets = {
UT: 0,
GMT: 0,
@@ -2356,12 +2432,13 @@
allowTime,
dateFormat,
timeFormat,
- tzFormat;
+ tzFormat,
+ isoDatesLen = isoDates.length,
+ isoTimesLen = isoTimes.length;
if (match) {
getParsingFlags(config).iso = true;
-
- for (i = 0, l = isoDates.length; i < l; i++) {
+ for (i = 0, l = isoDatesLen; i < l; i++) {
if (isoDates[i][1].exec(match[1])) {
dateFormat = isoDates[i][0];
allowTime = isoDates[i][2] !== false;
@@ -2373,7 +2450,7 @@
return;
}
if (match[3]) {
- for (i = 0, l = isoTimes.length; i < l; i++) {
+ for (i = 0, l = isoTimesLen; i < l; i++) {
if (isoTimes[i][1].exec(match[3])) {
// match[2] should be 'T' or space
timeFormat = (match[2] || ' ') + isoTimes[i][0];
@@ -2440,7 +2517,7 @@
function preprocessRFC2822(s) {
// Remove comments and folding whitespace and replace multiple-spaces with a single space
return s
- .replace(/\([^)]*\)|[\n\t]/g, ' ')
+ .replace(/\([^()]*\)|[\n\t]/g, ' ')
.replace(/(\s\s+)/g, ' ')
.replace(/^\s\s*/, '')
.replace(/\s\s*$/, '');
@@ -2540,8 +2617,7 @@
hooks.createFromInputFallback = deprecate(
'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
- 'discouraged and will be removed in an upcoming major release. Please refer to ' +
- 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
+ 'discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.',
function (config) {
config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
}
@@ -2754,17 +2830,16 @@
skipped,
stringLength = string.length,
totalParsedInputLength = 0,
- era;
+ era,
+ tokenLen;
tokens =
expandFormat(config._f, config._locale).match(formattingTokens) || [];
-
- for (i = 0; i < tokens.length; i++) {
+ tokenLen = tokens.length;
+ for (i = 0; i < tokenLen; i++) {
token = tokens[i];
parsedInput = (string.match(getParseRegexForToken(token, config)) ||
[])[0];
- // console.log('token', token, 'parsedInput', parsedInput,
- // 'regex', getParseRegexForToken(token, config));
if (parsedInput) {
skipped = string.substr(0, string.indexOf(parsedInput));
if (skipped.length > 0) {
@@ -2856,15 +2931,16 @@
i,
currentScore,
validFormatFound,
- bestFormatIsValid = false;
+ bestFormatIsValid = false,
+ configfLen = config._f.length;
- if (config._f.length === 0) {
+ if (configfLen === 0) {
getParsingFlags(config).invalidFormat = true;
config._d = new Date(NaN);
return;
}
- for (i = 0; i < config._f.length; i++) {
+ for (i = 0; i < configfLen; i++) {
currentScore = 0;
validFormatFound = false;
tempConfig = copyConfig({}, config);
@@ -3105,7 +3181,8 @@
function isDurationValid(m) {
var key,
unitHasDecimal = false,
- i;
+ i,
+ orderLen = ordering.length;
for (key in m) {
if (
hasOwnProp(m, key) &&
@@ -3118,7 +3195,7 @@
}
}
- for (i = 0; i < ordering.length; ++i) {
+ for (i = 0; i < orderLen; ++i) {
if (m[ordering[i]]) {
if (unitHasDecimal) {
return false; // only allow non-integers for smallest unit
@@ -3443,7 +3520,8 @@
// from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
// somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
// and further modified to allow for strings containing both week and day
- isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
+ isoRegex =
+ /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
function createDuration(input, key) {
var duration = input,
@@ -3664,9 +3742,10 @@
'ms',
],
i,
- property;
+ property,
+ propertyLen = properties.length;
- for (i = 0; i < properties.length; i += 1) {
+ for (i = 0; i < propertyLen; i += 1) {
property = properties[i];
propertyTest = propertyTest || hasOwnProp(input, property);
}
@@ -3713,22 +3792,25 @@
return diff < -6
? 'sameElse'
: diff < -1
- ? 'lastWeek'
- : diff < 0
- ? 'lastDay'
- : diff < 1
- ? 'sameDay'
- : diff < 2
- ? 'nextDay'
- : diff < 7
- ? 'nextWeek'
- : 'sameElse';
+ ? 'lastWeek'
+ : diff < 0
+ ? 'lastDay'
+ : diff < 1
+ ? 'sameDay'
+ : diff < 2
+ ? 'nextDay'
+ : diff < 7
+ ? 'nextWeek'
+ : 'sameElse';
}
function calendar$1(time, formats) {
// Support for single parameter, formats only overload to the calendar function
if (arguments.length === 1) {
- if (isMomentInput(arguments[0])) {
+ if (!arguments[0]) {
+ time = undefined;
+ formats = undefined;
+ } else if (isMomentInput(arguments[0])) {
time = arguments[0];
formats = undefined;
} else if (isCalendarSpec(arguments[0])) {
@@ -4286,19 +4368,17 @@
addRegexToken('NNNN', matchEraName);
addRegexToken('NNNNN', matchEraNarrow);
- addParseToken(['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], function (
- input,
- array,
- config,
- token
- ) {
- var era = config._locale.erasParse(input, token, config._strict);
- if (era) {
- getParsingFlags(config).era = era;
- } else {
- getParsingFlags(config).invalidEra = input;
+ addParseToken(
+ ['N', 'NN', 'NNN', 'NNNN', 'NNNNN'],
+ function (input, array, config, token) {
+ var era = config._locale.erasParse(input, token, config._strict);
+ if (era) {
+ getParsingFlags(config).era = era;
+ } else {
+ getParsingFlags(config).invalidEra = input;
+ }
}
- });
+ );
addRegexToken('y', matchUnsigned);
addRegexToken('yy', matchUnsigned);
@@ -4406,7 +4486,7 @@
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
- val = this.startOf('day').valueOf();
+ val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].name;
@@ -4426,7 +4506,7 @@
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
- val = this.startOf('day').valueOf();
+ val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].narrow;
@@ -4446,7 +4526,7 @@
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
- val = this.startOf('day').valueOf();
+ val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].abbr;
@@ -4469,7 +4549,7 @@
dir = eras[i].since <= eras[i].until ? +1 : -1;
// truncate time
- val = this.startOf('day').valueOf();
+ val = this.clone().startOf('day').valueOf();
if (
(eras[i].since <= val && val <= eras[i].until) ||
@@ -4529,16 +4609,22 @@
mixedPieces = [],
i,
l,
+ erasName,
+ erasAbbr,
+ erasNarrow,
eras = this.eras();
for (i = 0, l = eras.length; i < l; ++i) {
- namePieces.push(regexEscape(eras[i].name));
- abbrPieces.push(regexEscape(eras[i].abbr));
- narrowPieces.push(regexEscape(eras[i].narrow));
+ erasName = regexEscape(eras[i].name);
+ erasAbbr = regexEscape(eras[i].abbr);
+ erasNarrow = regexEscape(eras[i].narrow);
- mixedPieces.push(regexEscape(eras[i].name));
- mixedPieces.push(regexEscape(eras[i].abbr));
- mixedPieces.push(regexEscape(eras[i].narrow));
+ namePieces.push(erasName);
+ abbrPieces.push(erasAbbr);
+ narrowPieces.push(erasNarrow);
+ mixedPieces.push(erasName);
+ mixedPieces.push(erasAbbr);
+ mixedPieces.push(erasNarrow);
}
this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
@@ -4571,14 +4657,6 @@
// ALIASES
- addUnitAlias('weekYear', 'gg');
- addUnitAlias('isoWeekYear', 'GG');
-
- // PRIORITY
-
- addUnitPriority('weekYear', 1);
- addUnitPriority('isoWeekYear', 1);
-
// PARSING
addRegexToken('G', matchSigned);
@@ -4590,14 +4668,12 @@
addRegexToken('GGGGG', match1to6, match6);
addRegexToken('ggggg', match1to6, match6);
- addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (
- input,
- week,
- config,
- token
- ) {
- week[token.substr(0, 2)] = toInt(input);
- });
+ addWeekParseToken(
+ ['gggg', 'ggggg', 'GGGG', 'GGGGG'],
+ function (input, week, config, token) {
+ week[token.substr(0, 2)] = toInt(input);
+ }
+ );
addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
week[token] = hooks.parseTwoDigitYear(input);
@@ -4610,7 +4686,7 @@
this,
input,
this.week(),
- this.weekday(),
+ this.weekday() + this.localeData()._week.dow,
this.localeData()._week.dow,
this.localeData()._week.doy
);
@@ -4672,14 +4748,6 @@
addFormatToken('Q', 0, 'Qo', 'quarter');
- // ALIASES
-
- addUnitAlias('quarter', 'Q');
-
- // PRIORITY
-
- addUnitPriority('quarter', 7);
-
// PARSING
addRegexToken('Q', match1);
@@ -4699,16 +4767,9 @@
addFormatToken('D', ['DD', 2], 'Do', 'date');
- // ALIASES
-
- addUnitAlias('date', 'D');
-
- // PRIORITY
- addUnitPriority('date', 9);
-
// PARSING
- addRegexToken('D', match1to2);
+ addRegexToken('D', match1to2, match1to2NoLeadingZero);
addRegexToken('DD', match1to2, match2);
addRegexToken('Do', function (isStrict, locale) {
// TODO: Remove "ordinalParse" fallback in next major release.
@@ -4730,13 +4791,6 @@
addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
- // ALIASES
-
- addUnitAlias('dayOfYear', 'DDD');
-
- // PRIORITY
- addUnitPriority('dayOfYear', 4);
-
// PARSING
addRegexToken('DDD', match1to3);
@@ -4761,17 +4815,9 @@
addFormatToken('m', ['mm', 2], 0, 'minute');
- // ALIASES
-
- addUnitAlias('minute', 'm');
-
- // PRIORITY
-
- addUnitPriority('minute', 14);
-
// PARSING
- addRegexToken('m', match1to2);
+ addRegexToken('m', match1to2, match1to2HasZero);
addRegexToken('mm', match1to2, match2);
addParseToken(['m', 'mm'], MINUTE);
@@ -4783,17 +4829,9 @@
addFormatToken('s', ['ss', 2], 0, 'second');
- // ALIASES
-
- addUnitAlias('second', 's');
-
- // PRIORITY
-
- addUnitPriority('second', 15);
-
// PARSING
- addRegexToken('s', match1to2);
+ addRegexToken('s', match1to2, match1to2HasZero);
addRegexToken('ss', match1to2, match2);
addParseToken(['s', 'ss'], SECOND);
@@ -4831,14 +4869,6 @@
return this.millisecond() * 1000000;
});
- // ALIASES
-
- addUnitAlias('millisecond', 'ms');
-
- // PRIORITY
-
- addUnitPriority('millisecond', 16);
-
// PARSING
addRegexToken('S', match1to3, match1);
@@ -5146,12 +5176,12 @@
toInt((number % 100) / 10) === 1
? 'th'
: b === 1
- ? 'st'
- : b === 2
- ? 'nd'
- : b === 3
- ? 'rd'
- : 'th';
+ ? 'st'
+ : b === 2
+ ? 'nd'
+ : b === 3
+ ? 'rd'
+ : 'th';
return number + output;
},
});
@@ -5324,19 +5354,6 @@
}
}
- // TODO: Use this.as('ms')?
- function valueOf$1() {
- if (!this.isValid()) {
- return NaN;
- }
- return (
- this._milliseconds +
- this._days * 864e5 +
- (this._months % 12) * 2592e6 +
- toInt(this._months / 12) * 31536e6
- );
- }
-
function makeAs(alias) {
return function () {
return this.as(alias);
@@ -5351,7 +5368,8 @@
asWeeks = makeAs('w'),
asMonths = makeAs('M'),
asQuarters = makeAs('Q'),
- asYears = makeAs('y');
+ asYears = makeAs('y'),
+ valueOf$1 = asMilliseconds;
function clone$1() {
return createDuration(this);
@@ -5620,7 +5638,7 @@
//! moment.js
- hooks.version = '2.25.2';
+ hooks.version = '2.30.1';
setHookCallback(createLocal);