UNPKG

ngx-bootstrap-ci

Version:
1,593 lines (1,571 loc) • 925 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define('ngx-bootstrap/chronos', ['exports'], factory) : (factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].chronos = {}))); }(this, (function (exports) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes} 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} 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 {?} 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); } var /** @type {?} */ 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) { var /** @type {?} */ coercedNumber = +argumentForCoercion; var /** @type {?} */ value = 0; if (coercedNumber !== 0 && isFinite(coercedNumber)) { value = absFloor(coercedNumber); } return value; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ aliases = {}; var /** @type {?} */ _mapUnits = { date: 'day', hour: 'hours', minute: 'minutes', second: 'seconds', millisecond: 'milliseconds' }; /** * @param {?} unit * @param {?} shorthand * @return {?} */ function addUnitAlias(unit, shorthand) { var /** @type {?} */ lowerCase = unit.toLowerCase(); var /** @type {?} */ _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) { var /** @type {?} */ normalizedInput = {}; var /** @type {?} */ normalizedProp; var /** @type {?} */ 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} checked by tsc */ // place in new Date([array]) var /** @type {?} */ YEAR = 0; var /** @type {?} */ MONTH = 1; var /** @type {?} */ DATE = 2; var /** @type {?} */ HOUR = 3; var /** @type {?} */ MINUTE = 4; var /** @type {?} */ SECOND = 5; var /** @type {?} */ MILLISECOND = 6; var /** @type {?} */ WEEK = 7; var /** @type {?} */ WEEKDAY = 8; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} num * @param {?} targetLength * @param {?=} forceSign * @return {?} */ function zeroFill(num, targetLength, forceSign) { var /** @type {?} */ absNumber = "" + Math.abs(num); var /** @type {?} */ zerosToFill = targetLength - absNumber.length; var /** @type {?} */ sign = num >= 0; var /** @type {?} */ _sign = sign ? (forceSign ? '+' : '') : '-'; // todo: this is crazy slow var /** @type {?} */ _zeros = Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1); return (_sign + _zeros + absNumber); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ formatFunctions = {}; var /** @type {?} */ formatTokenFunctions = {}; // tslint:disable-next-line var /** @type {?} */ 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; /** * @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]] = function () { return zeroFill(callback.apply(null, arguments), padded[1], padded[2]); }; } if (ordinal) { formatTokenFunctions[ordinal] = function (date, opts) { return opts.locale.ordinal(callback.apply(null, arguments), token); }; } } /** * @param {?} format * @return {?} */ function makeFormatFunction(format) { var /** @type {?} */ array = format.match(formattingTokens); var /** @type {?} */ length = array.length; var /** @type {?} */ formatArr = new Array(length); for (var /** @type {?} */ i = 0; i < length; i++) { formatArr[i] = formatTokenFunctions[array[i]] ? formatTokenFunctions[array[i]] : removeFormattingTokens(array[i]); } return function (date, locale, isUTC, offset) { if (offset === void 0) { offset = 0; } var /** @type {?} */ output = ''; for (var /** @type {?} */ j = 0; j < length; j++) { output += isFunction(formatArr[j]) ? ((formatArr[j])).call(null, date, { format: format, locale: locale, isUTC: isUTC, offset: 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} checked by tsc */ /** * @param {?=} y * @param {?=} m * @param {?=} d * @return {?} */ function createUTCDate(y, m, d) { var /** @type {?} */ 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, d, h, M, s, ms) { if (m === void 0) { m = 0; } if (d === void 0) { d = 1; } if (h === void 0) { h = 0; } if (M === void 0) { M = 0; } if (s === void 0) { s = 0; } if (ms === void 0) { ms = 0; } var /** @type {?} */ 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} checked by tsc */ /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getHours(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCHours() : date.getHours(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMinutes(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCMinutes() : date.getMinutes(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getSeconds(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCSeconds() : date.getSeconds(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMilliseconds(date, isUTC) { if (isUTC === void 0) { 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) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCDay() : date.getDay(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getDate(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCDate() : date.getDate(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getMonth(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCMonth() : date.getMonth(); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getFullYear(date, isUTC) { if (isUTC === void 0) { isUTC = false; } return isUTC ? date.getUTCFullYear() : date.getFullYear(); } /** * @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 * @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} checked by tsc */ var /** @type {?} */ match1 = /\d/; // 0 - 9 var /** @type {?} */ match2 = /\d\d/; // 00 - 99 var /** @type {?} */ match3 = /\d{3}/; // 000 - 999 var /** @type {?} */ match4 = /\d{4}/; // 0000 - 9999 var /** @type {?} */ match6 = /[+-]?\d{6}/; // -999999 - 999999 var /** @type {?} */ match1to2 = /\d\d?/; // 0 - 99 var /** @type {?} */ match3to4 = /\d\d\d\d?/; // 999 - 9999 var /** @type {?} */ match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999 var /** @type {?} */ match1to3 = /\d{1,3}/; // 0 - 999 var /** @type {?} */ match1to4 = /\d{1,4}/; // 0 - 9999 var /** @type {?} */ match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999 var /** @type {?} */ matchUnsigned = /\d+/; // 0 - inf var /** @type {?} */ matchSigned = /[+-]?\d+/; // -inf - inf var /** @type {?} */ matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z var /** @type {?} */ 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 var /** @type {?} */ 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; var /** @type {?} */ regexes = {}; /** * @param {?} token * @param {?} regex * @param {?=} strictRegex * @return {?} */ function addRegexToken(token, regex, strictRegex) { if (isFunction(regex)) { regexes[token] = regex; return; } regexes[token] = function (isStrict, locale) { return (isStrict && strictRegex) ? strictRegex : regex; }; } /** * @param {?} token * @param {?} locale * @return {?} */ function getParseRegexForToken(token, locale) { var /** @type {?} */ _strict = false; if (!hasOwnProp(regexes, token)) { return new RegExp(unescapeFormat(token)); } return regexes[token](_strict, locale); } /** * @param {?} str * @return {?} */ function unescapeFormat(str) { // tslint:disable-next-line return regexEscape(str .replace('\\', '') .replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { return p1 || p2 || p3 || p4; })); } /** * @param {?} str * @return {?} */ function regexEscape(str) { return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ tokens = {}; /** * @param {?} token * @param {?} callback * @return {?} */ function addParseToken(token, callback) { var /** @type {?} */ _token = isString(token) ? [token] : token; var /** @type {?} */ func = callback; if (isNumber(callback)) { func = function (input, array, config) { array[callback] = toInt(input); return config; }; } if (isArray(_token) && isFunction(func)) { var /** @type {?} */ i = void 0; for (i = 0; i < _token.length; i++) { tokens[_token[i]] = func; } } } /** * @param {?} token * @param {?} callback * @return {?} */ function addWeekParseToken(token, callback) { addParseToken(token, 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} checked by tsc */ /* export function getPrioritizedUnits(unitsObj) { const units = []; let unit; for (unit in unitsObj) { if (unitsObj.hasOwnProperty(unit)) { units.push({ unit, priority: priorities[unit] }); } } units.sort(function (a, b) { return a.priority - b.priority; }); return units; } */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @return {?} */ function initDayOfMonth() { // FORMATTING addFormatToken('D', ['DD', 2, false], 'Do', function (date, opts) { return getDate(date, opts.isUTC) .toString(10); }); // ALIASES addUnitAlias('date', 'D'); // PARSING addRegexToken('D', match1to2); addRegexToken('DD', match1to2, match2); addRegexToken('Do', function (isStrict, locale) { return locale._dayOfMonthOrdinalParse || locale._ordinalParse; }); addParseToken(['D', 'DD'], DATE); addParseToken('Do', function (input, array, config) { array[DATE] = toInt(input.match(match1to2)[0]); return config; }); } /** * @fileoverview added by tsickle * @suppress {checkTypes} 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} checked by tsc */ /** * @param {?} date * @param {?} opts * @return {?} */ function getYear(date, opts) { return getFullYear(date, opts.isUTC).toString(); } /** * @return {?} */ function initYear() { addFormatToken('Y', null, null, function (date, opts) { var /** @type {?} */ y = getFullYear(date, opts.isUTC); return y <= 9999 ? y.toString(10) : "+" + y; }); addFormatToken(null, ['YY', 2, false], null, 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'); // 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, config) { array[YEAR] = input.length === 2 ? parseTwoDigitYear(input) : toInt(input); return config; }); addParseToken('YY', function (input, array, config) { array[YEAR] = parseTwoDigitYear(input); return config; }); addParseToken('Y', 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} checked by tsc */ /** * @param {?} year * @param {?} month * @return {?} */ function daysInMonth$1(year, month) { if (isNaN(year) || isNaN(month)) { return NaN; } var /** @type {?} */ modMonth = mod(month, 12); var /** @type {?} */ _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', function (date, opts) { return (getMonth(date, opts.isUTC) + 1).toString(10); }); addFormatToken('MMM', null, null, function (date, opts) { return opts.locale.monthsShort(date, opts.format, opts.isUTC); }); addFormatToken('MMMM', null, null, function (date, opts) { return opts.locale.months(date, opts.format, opts.isUTC); }); // ALIASES addUnitAlias('month', 'M'); // PARSING addRegexToken('M', match1to2); addRegexToken('MM', match1to2, match2); addRegexToken('MMM', function (isStrict, locale) { return locale.monthsShortRegex(isStrict); }); addRegexToken('MMMM', function (isStrict, locale) { return locale.monthsRegex(isStrict); }); addParseToken(['M', 'MM'], function (input, array, config) { array[MONTH] = toInt(input) - 1; return config; }); addParseToken(['MMM', 'MMMM'], function (input, array, config, token) { var /** @type {?} */ 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} checked by tsc */ var /** @type {?} */ defaultTimeUnit = { year: 0, month: 0, day: 0, hour: 0, minute: 0, seconds: 0 }; /** * @param {?} date * @param {?} unit * @return {?} */ function shiftDate(date, unit) { var /** @type {?} */ _unit = Object.assign({}, defaultTimeUnit, unit); var /** @type {?} */ year = date.getFullYear() + (_unit.year || 0); var /** @type {?} */ month = date.getMonth() + (_unit.month || 0); var /** @type {?} */ 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), getNum(date.getDate(), unit.day), 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 setMonth(date, value, isUTC) { var /** @type {?} */ 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 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} checked by tsc */ /** * @param {?} date * @return {?} */ function cloneDate(date) { return new Date(date.getTime()); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @param {?} date * @param {?} unit * @param {?=} isUTC * @return {?} */ function startOf(date, unit, isUTC) { var /** @type {?} */ _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: 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) { var /** @type {?} */ _unit = unit; // 'date' is an alias for 'day', so it should be considered as such. if (_unit === 'date') { _unit = 'day'; } var /** @type {?} */ start = startOf(date, _unit, isUTC); var /** @type {?} */ _step = add(start, 1, _unit === 'isoWeek' ? 'week' : _unit, isUTC); var /** @type {?} */ res = subtract(_step, 1, 'milliseconds', isUTC); return res; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @return {?} */ function initDayOfYear() { // FORMATTING addFormatToken('DDD', ['DDDD', 3, false], 'DDDo', function (date) { return getDayOfYear(date) .toString(10); }); // ALIASES addUnitAlias('dayOfYear', 'DDD'); addRegexToken('DDD', match1to3); addRegexToken('DDDD', match3); addParseToken(['DDD', 'DDDD'], function (input, array, config) { config._dayOfYear = toInt(input); return config; }); } /** * @param {?} date * @param {?=} isUTC * @return {?} */ function getDayOfYear(date, isUTC) { var /** @type {?} */ date1 = +startOf(date, 'day', isUTC); var /** @type {?} */ date2 = +startOf(date, 'year', isUTC); var /** @type {?} */ someDate = date1 - date2; var /** @type {?} */ oneDay = 1000 * 60 * 60 * 24; return Math.round(someDate / oneDay) + 1; } /** * @fileoverview added by tsickle * @suppress {checkTypes} 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) var /** @type {?} */ fwd = dow - doy + 7; // first-week day local weekday -- which local weekday is fwd var /** @type {?} */ fwdlw = (createUTCDate(year, 0, fwd).getUTCDay() - dow + 7) % 7; return -fwdlw + fwd - 1; } /** * @param {?} year * @param {?} week * @param {?} weekday * @param {?} dow * @param {?} doy * @return {?} */ function dayOfYearFromWeeks(year, week, weekday, dow, doy) { var /** @type {?} */ localWeekday = (7 + weekday - dow) % 7; var /** @type {?} */ weekOffset = firstWeekOffset(year, dow, doy); var /** @type {?} */ dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset; var /** @type {?} */ resYear; var /** @type {?} */ 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) { var /** @type {?} */ weekOffset = firstWeekOffset(getFullYear(date, isUTC), dow, doy); var /** @type {?} */ week = Math.floor((getDayOfYear(date, isUTC) - weekOffset - 1) / 7) + 1; var /** @type {?} */ resWeek; var /** @type {?} */ 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) { var /** @type {?} */ weekOffset = firstWeekOffset(year, dow, doy); var /** @type {?} */ weekOffsetNext = firstWeekOffset(year + 1, dow, doy); return (daysInYear(year) - weekOffset + weekOffsetNext) / 7; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ var /** @type {?} */ MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/; var /** @type {?} */ defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'); var /** @type {?} */ defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'); var /** @type {?} */ defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'); var /** @type {?} */ defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'); var /** @type {?} */ defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'); var /** @type {?} */ 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' }; var /** @type {?} */ defaultOrdinal = '%d'; var /** @type {?} */ defaultDayOfMonthOrdinalParse = /\d{1,2}/; var /** @type {?} */ defaultMonthsShortRegex = matchWord; var /** @type {?} */ defaultMonthsRegex = matchWord; var Locale = (function () { function Locale(config) { if (!!config) { this.set(config); } } /** * @param {?} config * @return {?} */ Locale.prototype.set = /** * @param {?} config * @return {?} */ function (config) { var /** @type {?} */ confKey; for (confKey in config) { if (!config.hasOwnProperty(confKey)) { continue; } var /** @type {?} */ prop = config[(confKey)]; var /** @type {?} */ key = ((isFunction(prop) ? confKey : "_" + confKey)); this[key] = /** @type {?} */ (prop); } this._config = config; }; /** * @param {?} key * @param {?} date * @param {?} now * @return {?} */ Locale.prototype.calendar = /** * @param {?} key * @param {?} date * @param {?} now * @return {?} */ function (key, date, now) { var /** @type {?} */ output = this._calendar[key] || this._calendar["sameElse"]; return isFunction(output) ? output.call(null, date, now) : output; }; /** * @param {?} key * @return {?} */ Locale.prototype.longDateFormat = /** * @param {?} key * @return {?} */ function (key) { var /** @type {?} */ format = this._longDateFormat[key]; var /** @type {?} */ 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]; }; Object.defineProperty(Locale.prototype, "invalidDate", { get: /** * @return {?} */ function () { return this._invalidDate; }, set: /** * @param {?} val * @return {?} */ function (val) { this._invalidDate = val; }, enumerable: true, configurable: true }); /** * @param {?} num * @param {?=} token * @return {?} */ Locale.prototype.ordinal = /** * @param {?} num * @param {?=} token * @return {?} */ function (num, token) { return this._ordinal.replace('%d', num.toString(10)); }; /** * @param {?} str * @return {?} */ Locale.prototype.preparse = /** * @param {?} str * @return {?} */ function (str) { return str; }; /** * @param {?} str * @return {?} */ Locale.prototype.postformat = /** * @param {?} str * @return {?} */ function (str) { return str; }; /** * @param {?} num * @param {?} withoutSuffix * @param {?} str * @param {?} isFuture * @return {?} */ Locale.prototype.relativeTime = /** * @param {?} num * @param {?} withoutSuffix * @param {?} str * @param {?} isFuture * @return {?} */ function (num, withoutSuffix, str, isFuture) { var /** @type {?} */ output = this._relativeTime[str]; return (isFunction(output)) ? output(num, withoutSuffix, str, isFuture) : output.replace(/%d/i, num.toString(10)); }; /** * @param {?} diff * @param {?} output * @return {?} */ Locale.prototype.pastFuture = /** * @param {?} diff * @param {?} output * @return {?} */ function (diff, output) { var /** @type {?} */ format = this._relativeTime[diff > 0 ? 'future' : 'past']; return isFunction(format) ? format(output) : format.replace(/%s/i, output); }; /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ Locale.prototype.months = /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ function (date, format, isUTC) { if (isUTC === void 0) { isUTC = false; } if (!date) { return isArray(this._months) ? this._months : this._months.standalone; } if (isArray(this._months)) { return this._months[getMonth(date, isUTC)]; } var /** @type {?} */ 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 {?} */ Locale.prototype.monthsShort = /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ function (date, format, isUTC) { if (isUTC === void 0) { isUTC = false; } if (!date) { return isArray(this._monthsShort) ? this._monthsShort : this._monthsShort.standalone; } if (isArray(this._monthsShort)) { return this._monthsShort[getMonth(date, isUTC)]; } var /** @type {?} */ key = MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'; return this._monthsShort[key][getMonth(date, isUTC)]; }; /** * @param {?} monthName * @param {?=} format * @param {?=} strict * @return {?} */ Locale.prototype.monthsParse = /** * @param {?} monthName * @param {?=} format * @param {?=} strict * @return {?} */ function (monthName, format, strict) { var /** @type {?} */ date; var /** @type {?} */ 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 var /** @type {?} */ 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]) { var /** @type {?} */ _months = this.months(date, '', true).replace('.', ''); var /** @type {?} */ _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' && ((this._longMonthsParse[i])).test(monthName)) { return i; } if (strict && format === 'MMM' && ((this._shortMonthsParse[i])).test(monthName)) { return i; } if (!strict && this._monthsParse[i].test(monthName)) { return i; } } }; /** * @param {?} isStrict * @return {?} */ Locale.prototype.monthsRegex = /** * @param {?} isStrict * @return {?} */ function (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 {?} */ Locale.prototype.monthsShortRegex = /** * @param {?} isStrict * @return {?} */ function (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 */ /** * Week * @param {?} date * @param {?=} isUTC * @return {?} */ Locale.prototype.week = /** * Week * @param {?} date * @param {?=} isUTC * @return {?} */ function (date, isUTC) { return weekOfYear(date, this._week.dow, this._week.doy, isUTC).week; }; /** * @return {?} */ Locale.prototype.firstDayOfWeek = /** * @return {?} */ function () { return this._week.dow; }; /** * @return {?} */ Locale.prototype.firstDayOfYear = /** * @return {?} */ function () { return this._week.doy; }; /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ Locale.prototype.weekdays = /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ function (date, format, isUTC) { if (!date) { return isArray(this._weekdays) ? this._weekdays : this._weekdays.standalone; } if (isArray(this._weekdays)) { return this._weekdays[getDay(date, isUTC)]; } var /** @type {?} */ _key = this._weekdays.isFormat.test(format) ? 'format' : 'standalone'; return this._weekdays[_key][getDay(date, isUTC)]; }; /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ Locale.prototype.weekdaysMin = /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ function (date, format, isUTC) { return date ? this._weekdaysMin[getDay(date, isUTC)] : this._weekdaysMin; }; /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ Locale.prototype.weekdaysShort = /** * @param {?=} date * @param {?=} format * @param {?=} isUTC * @return {?} */ function (date, format, isUTC) { return date ? this._weekdaysShort[getDay(date, isUTC)] : this._weekdaysShort; }; // proto.weekdaysParse = localeWeekdaysParse; /** * @param {?=} weekdayName * @param {?=} format * @param {?=} strict * @return {?} */ Locale.prototype.weekdaysParse = /** * @param {?=} weekdayName * @param {?=} format * @param {?=} strict * @return {?} */ function (weekdayName, format, strict) { var /** @type {?} */ i; var /** @type {?} */ 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 var /** @type {?} */ date = setDayOfWeek(new Date(Date.UTC(2000, 1)), i, null, true); if (strict && !this._fullWeek