UNPKG

ngx-bootstrap-fix-datepicker

Version:
1,908 lines (1,888 loc) 329 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} n * @param {?} x * @return {?} */ function mod(n, x) { return (n % x + x) % x; } /** * @param {?} num * @return {?} */ function absFloor(num) { return num < 0 ? Math.ceil(num) || 0 : Math.floor(num); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} str * @return {?} */ function isString(str) { return typeof str === 'string'; } /** * @param {?} value * @return {?} */ function isDate(value) { return value instanceof Date || Object.prototype.toString.call(value) === '[object Date]'; } /** * @param {?} value * @return {?} */ function isBoolean(value) { return value === true || value === false; } /** * @param {?} date * @return {?} */ function isDateValid(date) { return date && date.getTime && !isNaN(date.getTime()); } /** * @param {?} fn * @return {?} */ function isFunction(fn) { return (fn instanceof Function || Object.prototype.toString.call(fn) === '[object Function]'); } /** * @param {?=} value * @return {?} */ function isNumber(value) { return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]'; } /** * @template T * @param {?=} input * @return {?} */ function isArray(input) { return (input instanceof Array || Object.prototype.toString.call(input) === '[object Array]'); } /** * @template T * @param {?} a * @param {?} b * @return {?} */ function hasOwnProp(a /*object*/, b) { return Object.prototype.hasOwnProperty.call(a, b); } /** * @template T * @param {?} input * @return {?} */ function isObject(input /*object*/) { // IE8 will treat undefined and null as object if it wasn't for // input != null return (input != null && Object.prototype.toString.call(input) === '[object Object]'); } /** * @param {?} obj * @return {?} */ function isObjectEmpty(obj) { if (Object.getOwnPropertyNames) { return (Object.getOwnPropertyNames(obj).length === 0); } /** @type {?} */ let k; for (k in obj) { if (obj.hasOwnProperty(k)) { return false; } } return true; } /** * @param {?} input * @return {?} */ function isUndefined(input) { return input === void 0; } /** * @template T * @param {?} argumentForCoercion * @return {?} */ function toInt(argumentForCoercion) { /** @type {?} */ const coercedNumber = +argumentForCoercion; /** @type {?} */ let value = 0; if (coercedNumber !== 0 && isFinite(coercedNumber)) { value = absFloor(coercedNumber); } return value; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const aliases = {}; /** @type {?} */ const _mapUnits = { date: 'day', hour: 'hours', minute: 'minutes', second: 'seconds', millisecond: 'milliseconds' }; /** * @param {?} unit * @param {?} shorthand * @return {?} */ function addUnitAlias(unit, shorthand) { /** @type {?} */ const lowerCase = unit.toLowerCase(); /** @type {?} */ let _unit = unit; if (lowerCase in _mapUnits) { _unit = _mapUnits[lowerCase]; } aliases[lowerCase] = aliases[`${lowerCase}s`] = aliases[shorthand] = _unit; } /** * @param {?} units * @return {?} */ function normalizeUnits(units) { return isString(units) ? aliases[units] || aliases[units.toLowerCase()] : undefined; } /** * @param {?} inputObject * @return {?} */ function normalizeObjectUnits(inputObject) { /** @type {?} */ const normalizedInput = {}; /** @type {?} */ let normalizedProp; /** @type {?} */ let prop; for (prop in inputObject) { if (hasOwnProp(inputObject, prop)) { normalizedProp = normalizeUnits(prop); if (normalizedProp) { normalizedInput[normalizedProp] = inputObject[prop]; } } } return (/** @type {?} */ (normalizedInput)); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // place in new Date([array]) /** @type {?} */ const YEAR = 0; /** @type {?} */ const MONTH = 1; /** @type {?} */ const DATE = 2; /** @type {?} */ const HOUR = 3; /** @type {?} */ const MINUTE = 4; /** @type {?} */ const SECOND = 5; /** @type {?} */ const MILLISECOND = 6; /** @type {?} */ const WEEK = 7; /** @type {?} */ const WEEKDAY = 8; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} num * @param {?} targetLength * @param {?=} forceSign * @return {?} */ function zeroFill(num, targetLength, forceSign) { /** @type {?} */ const absNumber = `${Math.abs(num)}`; /** @type {?} */ const zerosToFill = targetLength - absNumber.length; /** @type {?} */ const sign = num >= 0; /** @type {?} */ const _sign = sign ? (forceSign ? '+' : '') : '-'; // todo: this is crazy slow /** @type {?} */ const _zeros = Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1); return (_sign + _zeros + absNumber); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ let formatFunctions = {}; /** @type {?} */ let formatTokenFunctions = {}; // tslint:disable-next-line /** @type {?} */ const formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g; // token: 'M' // padded: ['MM', 2] // ordinal: 'Mo' // callback: function () { this.month() + 1 } /** * @param {?} token * @param {?} padded * @param {?} ordinal * @param {?} callback * @return {?} */ function addFormatToken(token, padded, ordinal, callback) { if (token) { formatTokenFunctions[token] = callback; } if (padded) { formatTokenFunctions[padded[0]] = (/** * @return {?} */ function () { return zeroFill(callback.apply(null, arguments), padded[1], padded[2]); }); } if (ordinal) { formatTokenFunctions[ordinal] = (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return opts.locale.ordinal(callback.apply(null, arguments), token); }); } } /** * @param {?} format * @return {?} */ function makeFormatFunction(format) { /** @type {?} */ const array = format.match(formattingTokens); /** @type {?} */ const length = array.length; /** @type {?} */ const formatArr = new Array(length); for (let i = 0; i < length; i++) { formatArr[i] = formatTokenFunctions[array[i]] ? formatTokenFunctions[array[i]] : removeFormattingTokens(array[i]); } return (/** * @param {?} date * @param {?} locale * @param {?} isUTC * @param {?=} offset * @return {?} */ function (date, locale, isUTC, offset = 0) { /** @type {?} */ let output = ''; for (let j = 0; j < length; j++) { output += isFunction(formatArr[j]) ? ((/** @type {?} */ (formatArr[j]))).call(null, date, { format, locale, isUTC, offset }) : formatArr[j]; } return output; }); } /** * @param {?} input * @return {?} */ function removeFormattingTokens(input) { if (input.match(/\[[\s\S]/)) { return input.replace(/^\[|\]$/g, ''); } return input.replace(/\\/g, ''); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?=} y * @param {?=} m * @param {?=} d * @return {?} */ function createUTCDate(y, m, d) { /** @type {?} */ const date = new Date(Date.UTC.apply(null, arguments)); // the Date.UTC function remaps years 0-99 to 1900-1999 if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) { date.setUTCFullYear(y); } return date; } /** * @param {?=} y * @param {?=} m * @param {?=} d * @param {?=} h * @param {?=} M * @param {?=} s * @param {?=} ms * @return {?} */ function createDate(y, m = 0, d = 1, h = 0, M = 0, s = 0, ms = 0) { /** @type {?} */ const date = new Date(y, m, d, h, M, s, ms); // the date constructor remaps years 0-99 to 1900-1999 if (y < 100 && y >= 0 && isFinite(date.getFullYear())) { date.setFullYear(y); } return date; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getHours(date, isUTC = false) { return isUTC ? date.getUTCHours() : date.getHours(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMinutes(date, isUTC = false) { return isUTC ? date.getUTCMinutes() : date.getMinutes(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getSeconds(date, isUTC = false) { return isUTC ? date.getUTCSeconds() : date.getSeconds(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMilliseconds(date, isUTC = false) { return isUTC ? date.getUTCMilliseconds() : date.getMilliseconds(); } /** * @param {?} date * @return {?} */ function getTime(date) { return date.getTime(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getDay(date, isUTC = false) { return isUTC ? date.getUTCDay() : date.getDay(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getDate(date, isUTC = false) { return isUTC ? date.getUTCDate() : date.getDate(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMonth(date, isUTC = false) { return isUTC ? date.getUTCMonth() : date.getMonth(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getFullYear(date, isUTC = false) { return isUTC ? date.getUTCFullYear() : date.getFullYear(); } /** * @param {?} date * @return {?} */ function getUnixTime(date) { return Math.floor(date.valueOf() / 1000); } /** * @param {?} date * @return {?} */ function unix(date) { return Math.floor(date.valueOf() / 1000); } /** * @param {?} date * @return {?} */ function getFirstDayOfMonth(date) { return createDate(date.getFullYear(), date.getMonth(), 1, date.getHours(), date.getMinutes(), date.getSeconds()); } /** * @param {?} date * @return {?} */ function daysInMonth(date) { return _daysInMonth(date.getFullYear(), date.getMonth()); } /** * @param {?} year * @param {?} month * @return {?} */ function _daysInMonth(year, month) { return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); } /** * @param {?} date * @param {?} firstDayOfWeek * @return {?} */ function isFirstDayOfWeek(date, firstDayOfWeek) { return date.getDay() === firstDayOfWeek; } /** * @param {?} date1 * @param {?} date2 * @return {?} */ function isSameMonth(date1, date2) { if (!date1 || !date2) { return false; } return isSameYear(date1, date2) && getMonth(date1) === getMonth(date2); } /** * @param {?} date1 * @param {?} date2 * @return {?} */ function isSameYear(date1, date2) { if (!date1 || !date2) { return false; } return getFullYear(date1) === getFullYear(date2); } /** * @param {?} date1 * @param {?} date2 * @return {?} */ function isSameDay(date1, date2) { if (!date1 || !date2) { return false; } return (isSameYear(date1, date2) && isSameMonth(date1, date2) && getDate(date1) === getDate(date2)); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const match1 = /\d/; // 0 - 9 /** @type {?} */ const match2 = /\d\d/; // 00 - 99 /** @type {?} */ const match3 = /\d{3}/; // 000 - 999 /** @type {?} */ const match4 = /\d{4}/; // 0000 - 9999 /** @type {?} */ const match6 = /[+-]?\d{6}/; // -999999 - 999999 /** @type {?} */ const match1to2 = /\d\d?/; // 0 - 99 /** @type {?} */ const match3to4 = /\d\d\d\d?/; // 999 - 9999 /** @type {?} */ const match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999 /** @type {?} */ const match1to3 = /\d{1,3}/; // 0 - 999 /** @type {?} */ const match1to4 = /\d{1,4}/; // 0 - 9999 /** @type {?} */ const match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999 /** @type {?} */ const matchUnsigned = /\d+/; // 0 - inf /** @type {?} */ const matchSigned = /[+-]?\d+/; // -inf - inf /** @type {?} */ const matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z /** @type {?} */ const matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z /** @type {?} */ const 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 // tslint:disable-next-line /** @type {?} */ const matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i; /** @type {?} */ const regexes = {}; /** * @param {?} token * @param {?} regex * @param {?=} strictRegex * @return {?} */ function addRegexToken(token, regex, strictRegex) { if (isFunction(regex)) { regexes[token] = regex; return; } regexes[token] = (/** * @param {?} isStrict * @param {?} locale * @return {?} */ function (isStrict, locale) { return (isStrict && strictRegex) ? strictRegex : regex; }); } /** * @param {?} token * @param {?} locale * @return {?} */ function getParseRegexForToken(token, locale) { /** @type {?} */ const _strict = false; if (!hasOwnProp(regexes, token)) { return new RegExp(unescapeFormat(token)); } return regexes[token](_strict, locale); } // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript /** * @param {?} str * @return {?} */ function unescapeFormat(str) { // tslint:disable-next-line return regexEscape(str .replace('\\', '') .replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, (/** * @param {?} matched * @param {?} p1 * @param {?} p2 * @param {?} p3 * @param {?} p4 * @return {?} */ (matched, p1, p2, p3, p4) => p1 || p2 || p3 || p4))); } /** * @param {?} str * @return {?} */ function regexEscape(str) { return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const tokens = {}; /** * @param {?} token * @param {?} callback * @return {?} */ function addParseToken(token, callback) { /** @type {?} */ const _token = isString(token) ? [token] : token; /** @type {?} */ let func = callback; if (isNumber(callback)) { func = (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[callback] = toInt(input); return config; }); } if (isArray(_token) && isFunction(func)) { /** @type {?} */ let i; for (i = 0; i < _token.length; i++) { tokens[_token[i]] = func; } } } /** * @param {?} token * @param {?} callback * @return {?} */ function addWeekParseToken(token, callback) { addParseToken(token, (/** * @param {?} input * @param {?} array * @param {?} config * @param {?} _token * @return {?} */ function (input, array, config, _token) { config._w = config._w || {}; return callback(input, config._w, config, _token); })); } /** * @param {?} token * @param {?} input * @param {?} config * @return {?} */ function addTimeToArrayFromToken(token, input, config) { if (input != null && hasOwnProp(tokens, token)) { tokens[token](input, config._a, config, token); } return config; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const priorities = {}; /** * @param {?} unit * @param {?} priority * @return {?} */ function addUnitPriority(unit, priority) { priorities[unit] = priority; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @return {?} */ function initDayOfMonth() { // FORMATTING addFormatToken('D', ['DD', 2, false], 'Do', (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return getDate(date, opts.isUTC) .toString(10); })); // ALIASES addUnitAlias('date', 'D'); // PRIOROITY addUnitPriority('date', 9); // PARSING addRegexToken('D', match1to2); addRegexToken('DD', match1to2, match2); addRegexToken('Do', (/** * @param {?} isStrict * @param {?} locale * @return {?} */ function (isStrict, locale) { return locale._dayOfMonthOrdinalParse || locale._ordinalParse; })); addParseToken(['D', 'DD'], DATE); addParseToken('Do', (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[DATE] = toInt(input.match(match1to2)[0]); return config; })); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @return {?} */ function defaultParsingFlags() { // We need to deep clone this object. return { empty: false, unusedTokens: [], unusedInput: [], overflow: -2, charsLeftOver: 0, nullInput: false, invalidMonth: null, invalidFormat: false, userInvalidated: false, iso: false, parsedDateParts: [], meridiem: null, rfc2822: false, weekdayMismatch: false }; } /** * @param {?} config * @return {?} */ function getParsingFlags(config) { if (config._pf == null) { config._pf = defaultParsingFlags(); } return config._pf; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // FORMATTING /** * @param {?} date * @param {?} opts * @return {?} */ function getYear(date, opts) { if (opts.locale.getFullYear) { return opts.locale.getFullYear(date, opts.isUTC).toString(); } return getFullYear(date, opts.isUTC).toString(); } /** * @return {?} */ function initYear() { addFormatToken('Y', null, null, (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { /** @type {?} */ const y = getFullYear(date, opts.isUTC); return y <= 9999 ? y.toString(10) : `+${y}`; })); addFormatToken(null, ['YY', 2, false], null, (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return (getFullYear(date, opts.isUTC) % 100).toString(10); })); addFormatToken(null, ['YYYY', 4, false], null, getYear); addFormatToken(null, ['YYYYY', 5, false], null, getYear); addFormatToken(null, ['YYYYYY', 6, true], null, getYear); // 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', (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[YEAR] = input.length === 2 ? parseTwoDigitYear(input) : toInt(input); return config; })); addParseToken('YY', (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[YEAR] = parseTwoDigitYear(input); return config; })); addParseToken('Y', (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[YEAR] = parseInt(input, 10); return config; })); } /** * @param {?} input * @return {?} */ function parseTwoDigitYear(input) { return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); } /** * @param {?} year * @return {?} */ function daysInYear(year) { return isLeapYear(year) ? 366 : 365; } /** * @param {?} year * @return {?} */ function isLeapYear(year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // todo: this is duplicate, source in date-getters.ts /** * @param {?} year * @param {?} month * @return {?} */ function daysInMonth$1(year, month) { if (isNaN(year) || isNaN(month)) { return NaN; } /** @type {?} */ const modMonth = mod(month, 12); /** @type {?} */ const _year = year + (month - modMonth) / 12; return modMonth === 1 ? isLeapYear(_year) ? 29 : 28 : (31 - modMonth % 7 % 2); } /** * @return {?} */ function initMonth() { // FORMATTING addFormatToken('M', ['MM', 2, false], 'Mo', (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return (getMonth(date, opts.isUTC) + 1).toString(10); })); addFormatToken('MMM', null, null, (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return opts.locale.monthsShort(date, opts.format, opts.isUTC); })); addFormatToken('MMMM', null, null, (/** * @param {?} date * @param {?} opts * @return {?} */ function (date, opts) { return opts.locale.months(date, opts.format, opts.isUTC); })); // ALIASES addUnitAlias('month', 'M'); // PRIORITY addUnitPriority('month', 8); // PARSING addRegexToken('M', match1to2); addRegexToken('MM', match1to2, match2); addRegexToken('MMM', (/** * @param {?} isStrict * @param {?} locale * @return {?} */ function (isStrict, locale) { return locale.monthsShortRegex(isStrict); })); addRegexToken('MMMM', (/** * @param {?} isStrict * @param {?} locale * @return {?} */ function (isStrict, locale) { return locale.monthsRegex(isStrict); })); addParseToken(['M', 'MM'], (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { array[MONTH] = toInt(input) - 1; return config; })); addParseToken(['MMM', 'MMMM'], (/** * @param {?} input * @param {?} array * @param {?} config * @param {?} token * @return {?} */ function (input, array, config, token) { /** @type {?} */ const month = config._locale.monthsParse(input, token, config._strict); // if we didn't find a month name, mark the date as invalid. if (month != null) { array[MONTH] = month; } else { getParsingFlags(config).invalidMonth = !!input; } return config; })); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const defaultTimeUnit = { year: 0, month: 0, day: 0, hour: 0, minute: 0, seconds: 0 }; /** * @param {?} date * @param {?} unit * @return {?} */ function shiftDate(date, unit) { /** @type {?} */ const _unit = Object.assign({}, defaultTimeUnit, unit); /** @type {?} */ const year = date.getFullYear() + (_unit.year || 0); /** @type {?} */ const month = date.getMonth() + (_unit.month || 0); /** @type {?} */ let day = date.getDate() + (_unit.day || 0); if (_unit.month && !_unit.day) { day = Math.min(day, daysInMonth$1(year, month)); } return createDate(year, month, day, date.getHours() + (_unit.hour || 0), date.getMinutes() + (_unit.minute || 0), date.getSeconds() + (_unit.seconds || 0)); } /** * @param {?} date * @param {?} unit * @return {?} */ function setFullDate(date, unit) { return createDate(getNum(date.getFullYear(), unit.year), getNum(date.getMonth(), unit.month), 1, // day, to avoid issue with wrong months selection at the end of current month (#5371) getNum(date.getHours(), unit.hour), getNum(date.getMinutes(), unit.minute), getNum(date.getSeconds(), unit.seconds), getNum(date.getMilliseconds(), unit.milliseconds)); } /** * @param {?} def * @param {?=} num * @return {?} */ function getNum(def, num) { return isNumber(num) ? num : def; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setFullYear(date, value, isUTC) { /** @type {?} */ const _month = getMonth(date, isUTC); /** @type {?} */ const _date = getDate(date, isUTC); /** @type {?} */ const _year = getFullYear(date, isUTC); if (isLeapYear(_year) && _month === 1 && _date === 29) { /** @type {?} */ const _daysInMonth = daysInMonth$1(value, _month); isUTC ? date.setUTCFullYear(value, _month, _daysInMonth) : date.setFullYear(value, _month, _daysInMonth); } isUTC ? date.setUTCFullYear(value) : date.setFullYear(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setMonth(date, value, isUTC) { /** @type {?} */ const dayOfMonth = Math.min(getDate(date), daysInMonth$1(getFullYear(date), value)); isUTC ? date.setUTCMonth(value, dayOfMonth) : date.setMonth(value, dayOfMonth); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setDay(date, value, isUTC) { isUTC ? date.setUTCDate(value) : date.setDate(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setHours(date, value, isUTC) { isUTC ? date.setUTCHours(value) : date.setHours(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setMinutes(date, value, isUTC) { isUTC ? date.setUTCMinutes(value) : date.setMinutes(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setSeconds(date, value, isUTC) { isUTC ? date.setUTCSeconds(value) : date.setSeconds(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setMilliseconds(date, value, isUTC) { isUTC ? date.setUTCMilliseconds(value) : date.setMilliseconds(value); return date; } /** * @param {?} date * @param {?} value * @param {?=} isUTC * @return {?} */ function setDate(date, value, isUTC) { isUTC ? date.setUTCDate(value) : date.setDate(value); return date; } /** * @param {?} date * @param {?} value * @return {?} */ function setTime(date, value) { date.setTime(value); return date; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // fastest way to clone date // https://jsperf.com/clone-date-object2 /** * @param {?} date * @return {?} */ function cloneDate(date) { return new Date(date.getTime()); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} date * @param {?} unit * @param {?=} isUTC * @return {?} */ function startOf(date, unit, isUTC) { /** @type {?} */ const _date = cloneDate(date); // the following switch intentionally omits break keywords // to utilize falling through the cases. switch (unit) { case 'year': setMonth(_date, 0, isUTC); /* falls through */ case 'quarter': case 'month': setDate(_date, 1, isUTC); /* falls through */ case 'week': case 'isoWeek': case 'day': case 'date': setHours(_date, 0, isUTC); /* falls through */ case 'hours': setMinutes(_date, 0, isUTC); /* falls through */ case 'minutes': setSeconds(_date, 0, isUTC); /* falls through */ case 'seconds': setMilliseconds(_date, 0, isUTC); } // weeks are a special case if (unit === 'week') { setLocaleDayOfWeek(_date, 0, { isUTC }); } if (unit === 'isoWeek') { setISODayOfWeek(_date, 1); } // quarters are also special if (unit === 'quarter') { setMonth(_date, Math.floor(getMonth(_date, isUTC) / 3) * 3, isUTC); } return _date; } /** * @param {?} date * @param {?} unit * @param {?=} isUTC * @return {?} */ function endOf(date, unit, isUTC) { /** @type {?} */ let _unit = unit; // 'date' is an alias for 'day', so it should be considered as such. if (_unit === 'date') { _unit = 'day'; } /** @type {?} */ const start = startOf(date, _unit, isUTC); /** @type {?} */ const _step = add(start, 1, _unit === 'isoWeek' ? 'week' : _unit, isUTC); /** @type {?} */ const res = subtract(_step, 1, 'milliseconds', isUTC); return res; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @return {?} */ function initDayOfYear() { // FORMATTING addFormatToken('DDD', ['DDDD', 3, false], 'DDDo', (/** * @param {?} date * @return {?} */ function (date) { return getDayOfYear(date) .toString(10); })); // ALIASES addUnitAlias('dayOfYear', 'DDD'); // PRIORITY addUnitPriority('dayOfYear', 4); addRegexToken('DDD', match1to3); addRegexToken('DDDD', match3); addParseToken(['DDD', 'DDDD'], (/** * @param {?} input * @param {?} array * @param {?} config * @return {?} */ function (input, array, config) { config._dayOfYear = toInt(input); return config; })); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getDayOfYear(date, isUTC) { /** @type {?} */ const date1 = +startOf(date, 'day', isUTC); /** @type {?} */ const date2 = +startOf(date, 'year', isUTC); /** @type {?} */ const someDate = date1 - date2; /** @type {?} */ const oneDay = 1000 * 60 * 60 * 24; return Math.round(someDate / oneDay) + 1; } /** * @param {?} date * @param {?} input * @return {?} */ function setDayOfYear(date, input) { /** @type {?} */ const dayOfYear = getDayOfYear(date); return add(date, (input - dayOfYear), 'day'); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} year * @param {?} dow * @param {?} doy * @return {?} */ function firstWeekOffset(year, dow, doy) { // first-week day -- which january is always in the first week (4 for iso, 1 for other) /** @type {?} */ const fwd = dow - doy + 7; // first-week day local weekday -- which local weekday is fwd /** @type {?} */ const fwdlw = (createUTCDate(year, 0, fwd).getUTCDay() - dow + 7) % 7; return -fwdlw + fwd - 1; } // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday /** * @param {?} year * @param {?} week * @param {?} weekday * @param {?} dow * @param {?} doy * @return {?} */ function dayOfYearFromWeeks(year, week, weekday, dow, doy) { /** @type {?} */ const localWeekday = (7 + weekday - dow) % 7; /** @type {?} */ const weekOffset = firstWeekOffset(year, dow, doy); /** @type {?} */ const dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset; /** @type {?} */ let resYear; /** @type {?} */ let resDayOfYear; if (dayOfYear <= 0) { resYear = year - 1; resDayOfYear = daysInYear(resYear) + dayOfYear; } else if (dayOfYear > daysInYear(year)) { resYear = year + 1; resDayOfYear = dayOfYear - daysInYear(year); } else { resYear = year; resDayOfYear = dayOfYear; } return { year: resYear, dayOfYear: resDayOfYear }; } /** * @param {?} date * @param {?} dow * @param {?} doy * @param {?=} isUTC * @return {?} */ function weekOfYear(date, dow, doy, isUTC) { /** @type {?} */ const weekOffset = firstWeekOffset(getFullYear(date, isUTC), dow, doy); /** @type {?} */ const week = Math.floor((getDayOfYear(date, isUTC) - weekOffset - 1) / 7) + 1; /** @type {?} */ let resWeek; /** @type {?} */ let resYear; if (week < 1) { resYear = getFullYear(date, isUTC) - 1; resWeek = week + weeksInYear(resYear, dow, doy); } else if (week > weeksInYear(getFullYear(date, isUTC), dow, doy)) { resWeek = week - weeksInYear(getFullYear(date, isUTC), dow, doy); resYear = getFullYear(date, isUTC) + 1; } else { resYear = getFullYear(date, isUTC); resWeek = week; } return { week: resWeek, year: resYear }; } /** * @param {?} year * @param {?} dow * @param {?} doy * @return {?} */ function weeksInYear(year, dow, doy) { /** @type {?} */ const weekOffset = firstWeekOffset(year, dow, doy); /** @type {?} */ const weekOffsetNext = firstWeekOffset(year + 1, dow, doy); return (daysInYear(year) - weekOffset + weekOffsetNext) / 7; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function LocaleOptionsFormat() { } if (false) { /** @type {?} */ LocaleOptionsFormat.prototype.format; /** @type {?} */ LocaleOptionsFormat.prototype.standalone; /** @type {?|undefined} */ LocaleOptionsFormat.prototype.isFormat; } /** @type {?} */ const MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/; /** @type {?} */ const defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'); /** @type {?} */ const defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'); /** @type {?} */ const defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'); /** @type {?} */ const defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'); /** @type {?} */ const defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'); /** @type {?} */ const 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' }; /** @type {?} */ const defaultOrdinal = '%d'; /** @type {?} */ const defaultDayOfMonthOrdinalParse = /\d{1,2}/; /** @type {?} */ const defaultMonthsShortRegex = matchWord; /** @type {?} */ const defaultMonthsRegex = matchWord; /** * @record */ function LocaleData() { } if (false) { /** @type {?|undefined} */ LocaleData.prototype.abbr; /** @type {?|undefined} */ LocaleData.prototype.parentLocale; /** @type {?|undefined} */ LocaleData.prototype.months; /** @type {?|undefined} */ LocaleData.prototype.monthsShort; /** @type {?|undefined} */ LocaleData.prototype.monthsParseExact; /** @type {?|undefined} */ LocaleData.prototype.weekdays; /** @type {?|undefined} */ LocaleData.prototype.weekdaysShort; /** @type {?|undefined} */ LocaleData.prototype.weekdaysMin; /** @type {?|undefined} */ LocaleData.prototype.weekdaysParseExact; /** @type {?|undefined} */ LocaleData.prototype.longDateFormat; /** @type {?|undefined} */ LocaleData.prototype.calendar; /** @type {?|undefined} */ LocaleData.prototype.relativeTime; /** @type {?|undefined} */ LocaleData.prototype.dayOfMonthOrdinalParse; /** @type {?|undefined} */ LocaleData.prototype.ordinal; /** @type {?|undefined} */ LocaleData.prototype.week; /** @type {?|undefined} */ LocaleData.prototype.invalidDate; /** @type {?|undefined} */ LocaleData.prototype.monthsRegex; /** @type {?|undefined} */ LocaleData.prototype.monthsParse; /** @type {?|undefined} */ LocaleData.prototype.monthsShortRegex; /** @type {?|undefined} */ LocaleData.prototype.monthsStrictRegex; /** @type {?|undefined} */ LocaleData.prototype.monthsShortStrictRegex; /** @type {?|undefined} */ LocaleData.prototype.longMonthsParse; /** @type {?|undefined} */ LocaleData.prototype.shortMonthsParse; /** @type {?|undefined} */ LocaleData.prototype.meridiemParse; /** * @param {?} hour * @param {?} meridiem * @return {?} */ LocaleData.prototype.meridiemHour = function (hour, meridiem) { }; /** * @param {?} str * @return {?} */ LocaleData.prototype.preparse = function (str) { }; /** * @param {?} str * @return {?} */ LocaleData.prototype.postformat = function (str) { }; /** * @param {?} hour * @param {?=} minute * @param {?=} isLower * @return {?} */ LocaleData.prototype.meridiem = function (hour, minute, isLower) { }; /** * @param {?} input * @return {?} */ LocaleData.prototype.isPM = function (input) { }; /** * @param {?} date * @param {?} isUTC * @return {?} */ LocaleData.prototype.getFullYear = function (date, isUTC) { }; } class Locale { /** * @param {?} config */ constructor(config) { if (!!config) { this.set(config); } } /** * @param {?} config * @return {?} */ set(config) { /** @type {?} */ let confKey; for (confKey in config) { if (!config.hasOwnProperty(confKey)) { continue; } /** @type {?} */ const prop = config[(/** @type {?} */ (confKey))]; /** @type {?} */ const key = (/** @type {?} */ ((isFunction(prop) ? confKey : `_${confKey}`))); this[key] = (/** @type {?} */ (prop)); } this._config = config; } /** * @param {?} key * @param {?} date * @param {?} now * @return {?} */ calendar(key, date, now) { /** @type {?} */ const output = this._calendar[key] || this._calendar.sameElse; return isFunction(output) ? output.call(null, date, now) : output; } /** * @param {?} key * @return {?} */ longDateFormat(key) { /** @type {?} */ const format = this._longDateFormat[key]; /** @type {?} */ const formatUpper = this._longDateFormat[key.toUpperCase()]; if (format || !formatUpper) { return format; } this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, (/** * @param {?} val * @return {?} */ function (val) { return val.slice(1); })); return this._longDateFormat[key]; } /** * @return {?} */ get invalidDate() { return this._invalidDate; } /** * @param {?} val * @return {?} */ set invalidDate(val) { this._invalidDate = val; } /** * @param {?} num * @param {?=} token * @return {?} */ ordinal(num, token) { return this._ordinal.replace('%d', num.toString(10)); } /** * @param {?} str * @return {?} */ preparse(str) { return str; } /** * @param {?} date * @param {?=} isUTC * @return {?} */ getFullYear(date, isUTC = false) { return getFullYear(date, isUTC); } /** * @param {?} str * @return {?} */ postformat(str) { return str; } /** * @param {?} num * @param {?} withoutSuffix * @param {?} str * @param {?} isFuture * @return {?} */ relativeTime(num, withoutSuffix, str, isFuture) { /** @type {?} */ const output = this._relativeTime[str]; return (isFunction(output)) ? output(num, withoutSuffix, str, isFuture) : output.replace(/%d/i, num.toString(10)); } /** * @param {?} diff * @param {?} output * @return {?} */ pastFuture(diff, output) { /** @type {?} */ const format = this._relativeTime[diff > 0 ? 'future' : 'past']; return isFunction(format) ? format(output) : format.replace(/%s/i, output); } /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ months(date, format, isUTC = false) { if (!date) { return isArray(this._months) ? this._months : this._months.standalone; } if (isArray(this._months)) { return this._months[getMonth(date, isUTC)]; } /** @type {?} */ const key = (this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'; return this._months[key][getMonth(date, isUTC)]; } /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ monthsShort(date, format, isUTC = false) { if (!date) { return isArray(this._monthsShort) ? this._monthsShort : this._monthsShort.standalone; } if (isArray(this._monthsShort)) { return this._monthsShort[getMonth(date, isUTC)]; } /** @type {?} */ const key = MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'; return this._monthsShort[key][getMonth(date, isUTC)]; } /** * @param {?} monthName * @param {?=} format * @param {?=} strict * @return {?} */ monthsParse(monthName, format, strict) { /** @type {?} */ let date; /** @type {?} */ let regex; if (this._monthsParseExact) { return this.handleMonthStrictParse(monthName, format, strict); } if (!this._monthsParse) { this._monthsParse = []; this._longMonthsParse = []; this._shortMonthsParse = []; } // TODO: add sorting // Sorting makes sure if one month (or abbr) is a prefix of another // see sorting in computeMonthsParse /** @type {?} */ let i; for (i = 0; i < 12; i++) { // make the regex if we don't have it already date = new Date(Date.UTC(2000, i)); if (strict && !this._longMonthsParse[i]) { /** @type {?} */ const _months = this.months(date, '', true).replace('.', ''); /** @type {?} */ const _shortMonths = this.monthsShort(date, '', true).replace('.', ''); this._longMonthsParse[i] = new RegExp(`^${_months}$`, 'i'); this._shortMonthsParse[i] = new RegExp(`^${_shortMonths}$`, 'i'); } if (!strict && !this._monthsParse[i]) { regex = `^${this.months(date, '', true)}|^${this.monthsShort(date, '', true)}`; this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i'); } // test the regex if (strict && format === 'MMMM' && ((/** @type {?} */ (this._longMonthsParse[i]))).test(monthName)) { return i; } if (strict && format === 'MMM' && ((/** @type {?} */ (this._shortMonthsParse[i]))).test(monthName)) { return i; } if (!strict && this._monthsParse[i].test(monthName)) { return i; } } } /** * @param {?} isStrict * @return {?} */ monthsRegex(isStrict) { if (this._monthsParseExact) { if (!hasOwnProp(this, '_monthsRegex')) { this.computeMonthsParse(); } if (isStrict) { return this._monthsStrictRegex; } return this._monthsRegex; } if (!hasOwnProp(this, '_monthsRegex')) { this._monthsRegex = defaultMonthsRegex; } return this._monthsStrictRegex && isStrict ? this._monthsStrictRegex : this._monthsRegex; } /** * @param {?} isStrict * @return {?} */ monthsShortRegex(isStrict) { if (this._monthsParseExact) { if (!hasOwnProp(this, '_monthsRegex')) { this.computeMonthsParse(); } if (isStrict) { return this._monthsShortStrictRegex; } return this._monthsShortRegex; } if (!hasOwnProp(this, '_monthsShortRegex')) { this._monthsShortRegex = defaultMonthsShortRegex; } return this._monthsShortStrictRegex && isStrict ? this._monthsShortStrictRegex : this._monthsShortRegex; } /** * Week * @param {?} date * @param {?=} isUTC * @return {?} */ week(date, isUTC) { return weekOfYear(date, this._week.dow, this._week.doy, isUTC).week; } /** * @return {?} */ firstDayOfWeek() { return this._week.dow; } /** * @return {?} */ firstDayOfYear() { return this._week.doy; } /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ weekdays(date, format, isUTC) { if (!date) { return isArray(this._weekdays) ? this._weekdays : this._weekdays.standalone; } if (isArray(this._weekdays)) { return this._weekdays[getDay(date, isUTC)]; } /** @type {?} */ const _key = this._weekdays.isFormat.test(format) ? 'format' : 'standalone'; return this._weekdays[_key][getDay(date, isUTC)]; } /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ weekdaysMin(date, format, isUTC) { return date ? this._weekdaysMin[getDay(date, isUTC)] : this._weekdaysMin; } /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ weekdaysShort(date, format, isUTC) { return date ? this._weekdaysShort[getDay(date, isUTC)] : this._weekdaysShort; } // proto.weekdaysParse = localeWeekdaysParse; /** * @param {?=} weekdayName * @param {?=} format * @param {?=} strict * @return {?} */ weekdaysParse(weekdayName, format, strict) { /** @type {?} */ let i; /** @type {?} */ let regex; if (this._weekdaysParseExact) { return this.handleWeekStrictParse(weekdayName, format, strict); } if (!this._weekdaysParse) { this._weekdaysParse = []; this._minWeekdaysParse = []; this._shortWeekdaysParse = []; this._fullWeekdaysParse = []; } for (i = 0; i < 7; i++) { // make the regex if we don't have it already // fix: here is the issue /** @type {?} */ const date = setDayOfWeek(new Date(Date.UTC(2000, 1)), i, null, true); if (strict && !this._fullWeekdaysParse[i]) { this._fullWeekdaysParse[i] = new RegExp(`^${this.weekdays(date, '', true).replace('.', '\.?')}$`, 'i'); this._shortWeekdaysParse[i] = new RegExp(`^${this.weekdaysShort(date, '', true).replace('.', '\.?')}$`, 'i'); this._minWeekdaysParse[i] = new RegExp(`^${this.weekdaysMin(date, '', true).replace('.', '\.?')}$`, 'i'); } if (!this._weekdaysParse[i]) { regex = `^${this.weekdays(date, '', true)}|^${this.weekdaysShort(date, '', true)}|^${this.weekdaysMin(date, '', true)}`; this._weekdaysParse[