primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 145 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/button'), require('primeng/ripple'), require('primeng/dom'), require('primeng/api'), require('@angular/forms')) :
typeof define === 'function' && define.amd ? define('primeng/calendar', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/button', 'primeng/ripple', 'primeng/dom', 'primeng/api', '@angular/forms'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.calendar = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.button, global.primeng.ripple, global.primeng.dom, global.primeng.api, global.ng.forms));
}(this, (function (exports, i0, animations, i2, i3, i4, dom, i1, forms) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || from);
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
var CALENDAR_VALUE_ACCESSOR = {
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return Calendar; }),
multi: true
};
var Calendar = /** @class */ (function () {
function Calendar(el, renderer, cd, zone, config) {
this.el = el;
this.renderer = renderer;
this.cd = cd;
this.zone = zone;
this.config = config;
this.dateFormat = 'mm/dd/yy';
this.multipleSeparator = ',';
this.rangeSeparator = '-';
this.inline = false;
this.showOtherMonths = true;
this.icon = 'pi pi-calendar';
this.shortYearCutoff = '+10';
this.hourFormat = '24';
this.stepHour = 1;
this.stepMinute = 1;
this.stepSecond = 1;
this.showSeconds = false;
this.showOnFocus = true;
this.showWeek = false;
this.dataType = 'date';
this.selectionMode = 'single';
this.todayButtonStyleClass = 'p-button-text';
this.clearButtonStyleClass = 'p-button-text';
this.autoZIndex = true;
this.baseZIndex = 0;
this.keepInvalid = false;
this.hideOnDateTimeSelect = true;
this.numberOfMonths = 1;
this.view = 'date';
this.timeSeparator = ":";
this.focusTrap = true;
this.firstDayOfWeek = 0;
this.showTransitionOptions = '.12s cubic-bezier(0, 0, 0.2, 1)';
this.hideTransitionOptions = '.1s linear';
this.onFocus = new i0.EventEmitter();
this.onBlur = new i0.EventEmitter();
this.onClose = new i0.EventEmitter();
this.onSelect = new i0.EventEmitter();
this.onInput = new i0.EventEmitter();
this.onTodayClick = new i0.EventEmitter();
this.onClearClick = new i0.EventEmitter();
this.onMonthChange = new i0.EventEmitter();
this.onYearChange = new i0.EventEmitter();
this.onClickOutside = new i0.EventEmitter();
this.onShow = new i0.EventEmitter();
this.onModelChange = function () { };
this.onModelTouched = function () { };
this.inputFieldValue = null;
this.navigationState = null;
this.convertTo24Hour = function (hours, pm) {
if (this.hourFormat == '12') {
if (hours === 12) {
return (pm ? 12 : 0);
}
else {
return (pm ? hours + 12 : hours);
}
}
return hours;
};
}
Object.defineProperty(Calendar.prototype, "content", {
set: function (content) {
var _this = this;
this.contentViewChild = content;
if (this.contentViewChild) {
if (this.isMonthNavigate) {
Promise.resolve(null).then(function () { return _this.updateFocus(); });
this.isMonthNavigate = false;
}
else {
this.initFocusableCell();
}
}
},
enumerable: false,
configurable: true
});
;
Object.defineProperty(Calendar.prototype, "defaultDate", {
get: function () {
return this._defaultDate;
},
set: function (defaultDate) {
this._defaultDate = defaultDate;
if (this.initialized) {
var date = defaultDate || new Date();
this.currentMonth = date.getMonth();
this.currentYear = date.getFullYear();
this.initTime(date);
this.createMonths(this.currentMonth, this.currentYear);
}
},
enumerable: false,
configurable: true
});
;
Object.defineProperty(Calendar.prototype, "minDate", {
get: function () {
return this._minDate;
},
set: function (date) {
this._minDate = date;
if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
this.createMonths(this.currentMonth, this.currentYear);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "maxDate", {
get: function () {
return this._maxDate;
},
set: function (date) {
this._maxDate = date;
if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
this.createMonths(this.currentMonth, this.currentYear);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "disabledDates", {
get: function () {
return this._disabledDates;
},
set: function (disabledDates) {
this._disabledDates = disabledDates;
if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
this.createMonths(this.currentMonth, this.currentYear);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "disabledDays", {
get: function () {
return this._disabledDays;
},
set: function (disabledDays) {
this._disabledDays = disabledDays;
if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
this.createMonths(this.currentMonth, this.currentYear);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "yearRange", {
get: function () {
return this._yearRange;
},
set: function (yearRange) {
this._yearRange = yearRange;
if (yearRange) {
var years = yearRange.split(':');
var yearStart = parseInt(years[0]);
var yearEnd = parseInt(years[1]);
this.populateYearOptions(yearStart, yearEnd);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "showTime", {
get: function () {
return this._showTime;
},
set: function (showTime) {
this._showTime = showTime;
if (this.currentHour === undefined) {
this.initTime(this.value || new Date());
}
this.updateInputfield();
},
enumerable: false,
configurable: true
});
Object.defineProperty(Calendar.prototype, "locale", {
get: function () {
return this._locale;
},
set: function (newLocale) {
console.warn("Locale property has no effect, use new i18n API instead.");
},
enumerable: false,
configurable: true
});
Calendar.prototype.ngOnInit = function () {
var _this = this;
var date = this.defaultDate || new Date();
this.currentMonth = date.getMonth();
this.currentYear = date.getFullYear();
if (this.view === 'date') {
this.createWeekDays();
this.initTime(date);
this.createMonths(this.currentMonth, this.currentYear);
this.ticksTo1970 = (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000);
}
else if (this.view === 'month') {
this.createMonthPickerValues();
}
this.translationSubscription = this.config.translationObserver.subscribe(function () {
_this.createWeekDays();
});
this.initialized = true;
};
Calendar.prototype.ngAfterContentInit = function () {
var _this = this;
this.templates.forEach(function (item) {
switch (item.getType()) {
case 'date':
_this.dateTemplate = item.template;
break;
case 'disabledDate':
_this.disabledDateTemplate = item.template;
break;
case 'header':
_this.headerTemplate = item.template;
break;
case 'footer':
_this.footerTemplate = item.template;
break;
default:
_this.dateTemplate = item.template;
break;
}
});
};
Calendar.prototype.getTranslation = function (option) {
return this.config.getTranslation(option);
};
Calendar.prototype.populateYearOptions = function (start, end) {
this.yearOptions = [];
for (var i = start; i <= end; i++) {
this.yearOptions.push(i);
}
};
Calendar.prototype.createWeekDays = function () {
this.weekDays = [];
var dayIndex = this.firstDayOfWeek;
var dayLabels = this.getTranslation(i1.TranslationKeys.DAY_NAMES_MIN);
for (var i = 0; i < 7; i++) {
this.weekDays.push(dayLabels[dayIndex]);
dayIndex = (dayIndex == 6) ? 0 : ++dayIndex;
}
};
Calendar.prototype.createMonthPickerValues = function () {
this.monthPickerValues = [];
var monthLabels = this.getTranslation(i1.TranslationKeys.MONTH_NAMES_SHORT);
for (var i = 0; i <= 11; i++) {
this.monthPickerValues.push(monthLabels[i]);
}
};
Calendar.prototype.createMonths = function (month, year) {
this.months = this.months = [];
for (var i = 0; i < this.numberOfMonths; i++) {
var m = month + i;
var y = year;
if (m > 11) {
m = m % 11 - 1;
y = year + 1;
}
this.months.push(this.createMonth(m, y));
}
};
Calendar.prototype.getWeekNumber = function (date) {
var checkDate = new Date(date.getTime());
checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
var time = checkDate.getTime();
checkDate.setMonth(0);
checkDate.setDate(1);
return Math.floor(Math.round((time - checkDate.getTime()) / 86400000) / 7) + 1;
};
Calendar.prototype.createMonth = function (month, year) {
var dates = [];
var firstDay = this.getFirstDayOfMonthIndex(month, year);
var daysLength = this.getDaysCountInMonth(month, year);
var prevMonthDaysLength = this.getDaysCountInPrevMonth(month, year);
var dayNo = 1;
var today = new Date();
var weekNumbers = [];
var monthRows = Math.ceil((daysLength + firstDay) / 7);
for (var i = 0; i < monthRows; i++) {
var week = [];
if (i == 0) {
for (var j = (prevMonthDaysLength - firstDay + 1); j <= prevMonthDaysLength; j++) {
var prev = this.getPreviousMonthAndYear(month, year);
week.push({ day: j, month: prev.month, year: prev.year, otherMonth: true,
today: this.isToday(today, j, prev.month, prev.year), selectable: this.isSelectable(j, prev.month, prev.year, true) });
}
var remainingDaysLength = 7 - week.length;
for (var j = 0; j < remainingDaysLength; j++) {
week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year),
selectable: this.isSelectable(dayNo, month, year, false) });
dayNo++;
}
}
else {
for (var j = 0; j < 7; j++) {
if (dayNo > daysLength) {
var next = this.getNextMonthAndYear(month, year);
week.push({ day: dayNo - daysLength, month: next.month, year: next.year, otherMonth: true,
today: this.isToday(today, dayNo - daysLength, next.month, next.year),
selectable: this.isSelectable((dayNo - daysLength), next.month, next.year, true) });
}
else {
week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year),
selectable: this.isSelectable(dayNo, month, year, false) });
}
dayNo++;
}
}
if (this.showWeek) {
weekNumbers.push(this.getWeekNumber(new Date(week[0].year, week[0].month, week[0].day)));
}
dates.push(week);
}
return {
month: month,
year: year,
dates: dates,
weekNumbers: weekNumbers
};
};
Calendar.prototype.initTime = function (date) {
this.pm = date.getHours() > 11;
if (this.showTime) {
this.currentMinute = date.getMinutes();
this.currentSecond = date.getSeconds();
this.setCurrentHourPM(date.getHours());
}
else if (this.timeOnly) {
this.currentMinute = 0;
this.currentHour = 0;
this.currentSecond = 0;
}
};
Calendar.prototype.navBackward = function (event) {
var _this = this;
event.stopPropagation();
if (this.disabled) {
event.preventDefault();
return;
}
this.isMonthNavigate = true;
if (this.view === 'month') {
this.decrementYear();
setTimeout(function () {
_this.updateFocus();
}, 1);
}
else {
if (this.currentMonth === 0) {
this.currentMonth = 11;
this.decrementYear();
}
else {
this.currentMonth--;
}
this.onMonthChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
this.createMonths(this.currentMonth, this.currentYear);
}
};
Calendar.prototype.navForward = function (event) {
var _this = this;
event.stopPropagation();
if (this.disabled) {
event.preventDefault();
return;
}
this.isMonthNavigate = true;
if (this.view === 'month') {
this.incrementYear();
setTimeout(function () {
_this.updateFocus();
}, 1);
}
else {
if (this.currentMonth === 11) {
this.currentMonth = 0;
this.incrementYear();
}
else {
this.currentMonth++;
}
this.onMonthChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
this.createMonths(this.currentMonth, this.currentYear);
}
};
Calendar.prototype.decrementYear = function () {
this.currentYear--;
if (this.yearNavigator && this.currentYear < this.yearOptions[0]) {
var difference = this.yearOptions[this.yearOptions.length - 1] - this.yearOptions[0];
this.populateYearOptions(this.yearOptions[0] - difference, this.yearOptions[this.yearOptions.length - 1] - difference);
}
};
Calendar.prototype.incrementYear = function () {
this.currentYear++;
if (this.yearNavigator && this.currentYear > this.yearOptions[this.yearOptions.length - 1]) {
var difference = this.yearOptions[this.yearOptions.length - 1] - this.yearOptions[0];
this.populateYearOptions(this.yearOptions[0] + difference, this.yearOptions[this.yearOptions.length - 1] + difference);
}
};
Calendar.prototype.onDateSelect = function (event, dateMeta) {
var _this = this;
if (this.disabled || !dateMeta.selectable) {
event.preventDefault();
return;
}
if (this.isMultipleSelection() && this.isSelected(dateMeta)) {
this.value = this.value.filter(function (date, i) {
return !_this.isDateEquals(date, dateMeta);
});
if (this.value.length === 0) {
this.value = null;
}
this.updateModel(this.value);
}
else {
if (this.shouldSelectDate(dateMeta)) {
this.selectDate(dateMeta);
}
}
if (this.isSingleSelection() && this.hideOnDateTimeSelect) {
setTimeout(function () {
event.preventDefault();
_this.hideOverlay();
if (_this.mask) {
_this.disableModality();
}
_this.cd.markForCheck();
}, 150);
}
this.updateInputfield();
event.preventDefault();
};
Calendar.prototype.shouldSelectDate = function (dateMeta) {
if (this.isMultipleSelection())
return this.maxDateCount != null ? this.maxDateCount > (this.value ? this.value.length : 0) : true;
else
return true;
};
Calendar.prototype.onMonthSelect = function (event, index) {
if (!dom.DomHandler.hasClass(event.target, 'p-disabled')) {
this.onDateSelect(event, { year: this.currentYear, month: index, day: 1, selectable: true });
}
};
Calendar.prototype.updateInputfield = function () {
var formattedValue = '';
if (this.value) {
if (this.isSingleSelection()) {
formattedValue = this.formatDateTime(this.value);
}
else if (this.isMultipleSelection()) {
for (var i = 0; i < this.value.length; i++) {
var dateAsString = this.formatDateTime(this.value[i]);
formattedValue += dateAsString;
if (i !== (this.value.length - 1)) {
formattedValue += this.multipleSeparator + ' ';
}
}
}
else if (this.isRangeSelection()) {
if (this.value && this.value.length) {
var startDate = this.value[0];
var endDate = this.value[1];
formattedValue = this.formatDateTime(startDate);
if (endDate) {
formattedValue += ' ' + this.rangeSeparator + ' ' + this.formatDateTime(endDate);
}
}
}
}
this.inputFieldValue = formattedValue;
this.updateFilledState();
if (this.inputfieldViewChild && this.inputfieldViewChild.nativeElement) {
this.inputfieldViewChild.nativeElement.value = this.inputFieldValue;
}
};
Calendar.prototype.formatDateTime = function (date) {
var formattedValue = null;
if (date) {
if (this.timeOnly) {
formattedValue = this.formatTime(date);
}
else {
formattedValue = this.formatDate(date, this.getDateFormat());
if (this.showTime) {
formattedValue += ' ' + this.formatTime(date);
}
}
}
return formattedValue;
};
Calendar.prototype.setCurrentHourPM = function (hours) {
if (this.hourFormat == '12') {
this.pm = hours > 11;
if (hours >= 12) {
this.currentHour = (hours == 12) ? 12 : hours - 12;
}
else {
this.currentHour = (hours == 0) ? 12 : hours;
}
}
else {
this.currentHour = hours;
}
};
Calendar.prototype.selectDate = function (dateMeta) {
var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
if (this.showTime) {
if (this.hourFormat == '12') {
if (this.currentHour === 12)
date.setHours(this.pm ? 12 : 0);
else
date.setHours(this.pm ? this.currentHour + 12 : this.currentHour);
}
else {
date.setHours(this.currentHour);
}
date.setMinutes(this.currentMinute);
date.setSeconds(this.currentSecond);
}
if (this.minDate && this.minDate > date) {
date = this.minDate;
this.setCurrentHourPM(date.getHours());
this.currentMinute = date.getMinutes();
this.currentSecond = date.getSeconds();
}
if (this.maxDate && this.maxDate < date) {
date = this.maxDate;
this.setCurrentHourPM(date.getHours());
this.currentMinute = date.getMinutes();
this.currentSecond = date.getSeconds();
}
if (this.isSingleSelection()) {
this.updateModel(date);
}
else if (this.isMultipleSelection()) {
this.updateModel(this.value ? __spreadArray(__spreadArray([], __read(this.value)), [date]) : [date]);
}
else if (this.isRangeSelection()) {
if (this.value && this.value.length) {
var startDate = this.value[0];
var endDate = this.value[1];
if (!endDate && date.getTime() >= startDate.getTime()) {
endDate = date;
}
else {
startDate = date;
endDate = null;
}
this.updateModel([startDate, endDate]);
}
else {
this.updateModel([date, null]);
}
}
this.onSelect.emit(date);
};
Calendar.prototype.updateModel = function (value) {
var _this = this;
this.value = value;
if (this.dataType == 'date') {
this.onModelChange(this.value);
}
else if (this.dataType == 'string') {
if (this.isSingleSelection()) {
this.onModelChange(this.formatDateTime(this.value));
}
else {
var stringArrValue = null;
if (this.value) {
stringArrValue = this.value.map(function (date) { return _this.formatDateTime(date); });
}
this.onModelChange(stringArrValue);
}
}
};
Calendar.prototype.getFirstDayOfMonthIndex = function (month, year) {
var day = new Date();
day.setDate(1);
day.setMonth(month);
day.setFullYear(year);
var dayIndex = day.getDay() + this.getSundayIndex();
return dayIndex >= 7 ? dayIndex - 7 : dayIndex;
};
Calendar.prototype.getDaysCountInMonth = function (month, year) {
return 32 - this.daylightSavingAdjust(new Date(year, month, 32)).getDate();
};
Calendar.prototype.getDaysCountInPrevMonth = function (month, year) {
var prev = this.getPreviousMonthAndYear(month, year);
return this.getDaysCountInMonth(prev.month, prev.year);
};
Calendar.prototype.getPreviousMonthAndYear = function (month, year) {
var m, y;
if (month === 0) {
m = 11;
y = year - 1;
}
else {
m = month - 1;
y = year;
}
return { 'month': m, 'year': y };
};
Calendar.prototype.getNextMonthAndYear = function (month, year) {
var m, y;
if (month === 11) {
m = 0;
y = year + 1;
}
else {
m = month + 1;
y = year;
}
return { 'month': m, 'year': y };
};
Calendar.prototype.getSundayIndex = function () {
return this.firstDayOfWeek > 0 ? 7 - this.firstDayOfWeek : 0;
};
Calendar.prototype.isSelected = function (dateMeta) {
var e_1, _a;
if (this.value) {
if (this.isSingleSelection()) {
return this.isDateEquals(this.value, dateMeta);
}
else if (this.isMultipleSelection()) {
var selected = false;
try {
for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
var date = _c.value;
selected = this.isDateEquals(date, dateMeta);
if (selected) {
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return selected;
}
else if (this.isRangeSelection()) {
if (this.value[1])
return this.isDateEquals(this.value[0], dateMeta) || this.isDateEquals(this.value[1], dateMeta) || this.isDateBetween(this.value[0], this.value[1], dateMeta);
else
return this.isDateEquals(this.value[0], dateMeta);
}
}
else {
return false;
}
};
Calendar.prototype.isMonthSelected = function (month) {
var day = this.value ? (Array.isArray(this.value) ? this.value[0].getDate() : this.value.getDate()) : 1;
return this.isSelected({ year: this.currentYear, month: month, day: day, selectable: true });
};
Calendar.prototype.isDateEquals = function (value, dateMeta) {
if (value)
return value.getDate() === dateMeta.day && value.getMonth() === dateMeta.month && value.getFullYear() === dateMeta.year;
else
return false;
};
Calendar.prototype.isDateBetween = function (start, end, dateMeta) {
var between = false;
if (start && end) {
var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
return start.getTime() <= date.getTime() && end.getTime() >= date.getTime();
}
return between;
};
Calendar.prototype.isSingleSelection = function () {
return this.selectionMode === 'single';
};
Calendar.prototype.isRangeSelection = function () {
return this.selectionMode === 'range';
};
Calendar.prototype.isMultipleSelection = function () {
return this.selectionMode === 'multiple';
};
Calendar.prototype.isToday = function (today, day, month, year) {
return today.getDate() === day && today.getMonth() === month && today.getFullYear() === year;
};
Calendar.prototype.isSelectable = function (day, month, year, otherMonth) {
var validMin = true;
var validMax = true;
var validDate = true;
var validDay = true;
if (otherMonth && !this.selectOtherMonths) {
return false;
}
if (this.minDate) {
if (this.minDate.getFullYear() > year) {
validMin = false;
}
else if (this.minDate.getFullYear() === year) {
if (this.minDate.getMonth() > month) {
validMin = false;
}
else if (this.minDate.getMonth() === month) {
if (this.minDate.getDate() > day) {
validMin = false;
}
}
}
}
if (this.maxDate) {
if (this.maxDate.getFullYear() < year) {
validMax = false;
}
else if (this.maxDate.getFullYear() === year) {
if (this.maxDate.getMonth() < month) {
validMax = false;
}
else if (this.maxDate.getMonth() === month) {
if (this.maxDate.getDate() < day) {
validMax = false;
}
}
}
}
if (this.disabledDates) {
validDate = !this.isDateDisabled(day, month, year);
}
if (this.disabledDays) {
validDay = !this.isDayDisabled(day, month, year);
}
return validMin && validMax && validDate && validDay;
};
Calendar.prototype.isDateDisabled = function (day, month, year) {
var e_2, _a;
if (this.disabledDates) {
try {
for (var _b = __values(this.disabledDates), _c = _b.next(); !_c.done; _c = _b.next()) {
var disabledDate = _c.value;
if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) {
return true;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
}
return false;
};
Calendar.prototype.isDayDisabled = function (day, month, year) {
if (this.disabledDays) {
var weekday = new Date(year, month, day);
var weekdayNumber = weekday.getDay();
return this.disabledDays.indexOf(weekdayNumber) !== -1;
}
return false;
};
Calendar.prototype.onInputFocus = function (event) {
this.focus = true;
if (this.showOnFocus) {
this.showOverlay();
}
this.onFocus.emit(event);
};
Calendar.prototype.onInputClick = function () {
if (this.overlay && this.autoZIndex) {
this.overlay.style.zIndex = String(this.baseZIndex + (++dom.DomHandler.zindex));
}
if (this.showOnFocus && !this.overlayVisible) {
this.showOverlay();
}
};
Calendar.prototype.onInputBlur = function (event) {
this.focus = false;
this.onBlur.emit(event);
if (!this.keepInvalid) {
this.updateInputfield();
}
this.onModelTouched();
};
Calendar.prototype.onButtonClick = function (event, inputfield) {
if (!this.overlayVisible) {
inputfield.focus();
this.showOverlay();
}
else {
this.hideOverlay();
}
};
Calendar.prototype.onPrevButtonClick = function (event) {
this.navigationState = { backward: true, button: true };
this.navBackward(event);
};
Calendar.prototype.onNextButtonClick = function (event) {