define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CalendarContext = (function () {
function CalendarContext(parent, calendar) {
this.defaultHolidays = [];
this.sortedDefaultHolidays = [];
this.exceptionDateSet = new Set();
this.exceptionsRanges = [];
this.parent = parent;
this.calendar = calendar;
this.initialize();
}
CalendarContext.prototype.initialize = function () {
this.buildDefaultHolidays();
this.buildExceptionsCollection();
};
CalendarContext.prototype.buildDefaultHolidays = function () {
var holidays = this.calendar['propName'] === 'projectCalendar' ? this.parent.calendarModule.holidays : this.calendar.holidays;
var overrides = this.calendar.exceptions;
for (var i = 0; i < holidays.length; i++) {
var holiday = holidays[i];
var fromDate = holiday.from ? new Date(holiday.from) : new Date(holiday.to);
var toDate = holiday.to ? new Date(holiday.to) : new Date(holiday.from);
for (var d = new Date(fromDate); d <= toDate; d.setDate(d.getDate() + 1)) {
var timestamp = new Date(d).setHours(0, 0, 0, 0);
var isOverridden = false;
for (var j = 0; j < overrides.length; j++) {
var overrideDate = new Date(overrides[j].from).setHours(0, 0, 0, 0);
if (overrideDate === timestamp) {
isOverridden = true;
break;
}
}
if (!isOverridden) {
this.defaultHolidays.push(timestamp);
}
}
}
this.sortedDefaultHolidays = this.defaultHolidays.slice().sort(function (a, b) { return a - b; });
};
CalendarContext.prototype.buildExceptionsCollection = function () {
var overrides = this.calendar.exceptions;
for (var i = 0; i < overrides.length; i++) {
var override = overrides[i];
var fromDate = new Date(override.from);
var toDate = new Date(override.to);
var id = "exception_" + i;
this.exceptionsRanges.push({
id: id,
from: fromDate,
to: toDate
});
for (var d = new Date(fromDate); d <= toDate; d.setDate(d.getDate() + 1)) {
this.exceptionDateSet.add(new Date(d).setHours(0, 0, 0, 0));
}
}
};
CalendarContext.prototype.getExceptionForDate = function (date) {
var timestamp = new Date(date.getTime()).setHours(0, 0, 0, 0);
return this.exceptionDateSet.has(timestamp);
};
return CalendarContext;
}());
exports.CalendarContext = CalendarContext;
});
|