all files / base/ calendar-module.js

98.44% Statements 63/64
89.29% Branches 25/28
100% Functions 7/7
98.44% Lines 63/64
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95   1953× 1953× 1953×   285× 285× 285× 251×   34× 33× 38× 31×                 73× 73× 146× 146×   73× 73× 111× 111× 36×   75×     75× 75× 75× 75×     73×   37× 37× 37× 37×         36×     36× 36× 36× 35×   36×     36×   37×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CalendarModule = (function () {
        function CalendarModule(parent) {
            this.holidays = [];
            this.workingTime = [];
            this.parent = parent;
        }
        CalendarModule.prototype.getCalendarById = function (id) {
            var taskCalendars = this.parent.calendarSettings.taskCalendars;
            var projectCalendar = this.parent.calendarSettings.projectCalendar;
            if (!id) {
                return projectCalendar;
            }
            if (taskCalendars && taskCalendars.length > 0) {
                for (var i = 0; i < taskCalendars.length; i++) {
                    if (taskCalendars[i].calendarId === id) {
                        return taskCalendars[i];
                    }
                }
            }
            else {
                return projectCalendar;
            }
            return projectCalendar;
        };
        CalendarModule.prototype.getDirectEndDate = function (startDate, duration) {
            if (duration < 0) {
                return startDate;
            }
            var resultDate = new Date(startDate.getTime());
            resultDate.setDate(resultDate.getDate() + (duration - 1));
            var exception = this.parent.defaultCalendarContext.getExceptionForDate(resultDate);
            var endTime = exception.hasException ? exception.data.endTime : this.parent.defaultEndTime;
            var hours = Math.floor(endTime / 3600);
            var minutes = Math.floor((endTime % 3600) / 60);
            var seconds = endTime % 60;
            resultDate.setHours(hours, minutes, seconds, 0);
            return resultDate;
        };
        CalendarModule.prototype.calculateDayWidth = function (ranges, startSec, endSec, perDayWidth) {
            var totalSeconds = 0;
            for (var _i = 0, ranges_1 = ranges; _i < ranges_1.length; _i++) {
                var r = ranges_1[_i];
                totalSeconds += (r.to - r.from);
            }
            var coveredSeconds = 0;
            for (var _a = 0, ranges_2 = ranges; _a < ranges_2.length; _a++) {
                var r = ranges_2[_a];
                if (endSec <= r.from) {
                    break;
                }
                Iif (startSec >= r.to) {
                    continue;
                }
                var effectiveStart = Math.max(startSec, r.from);
                var effectiveEnd = Math.min(endSec, r.to);
                Eif (effectiveEnd > effectiveStart) {
                    coveredSeconds += (effectiveEnd - effectiveStart);
                }
            }
            return (coveredSeconds / totalSeconds) * perDayWidth;
        };
        CalendarModule.prototype.calculateWidthWithExceptions = function (sDate, eDate, startException, endException) {
            var width = 0;
            var sameDay = sDate.toDateString() === eDate.toDateString();
            var ranges;
            if (sameDay) {
                ranges = startException.hasException
                    ? startException.data.workingRange
                    : this.parent.workingTimeRanges;
                width = this.calculateDayWidth(ranges, this.parent.dataOperation['getSecondsInDecimal'](sDate), this.parent.dataOperation['getSecondsInDecimal'](eDate), this.parent.perDayWidth);
            }
            else {
                ranges = startException.hasException
                    ? startException.data.workingRange
                    : this.parent.workingTimeRanges;
                width += this.calculateDayWidth(ranges, this.parent.dataOperation['getSecondsInDecimal'](sDate), ranges[ranges.length - 1].to, this.parent.perDayWidth);
                var daysBetween = Math.floor((eDate.getTime() - sDate.getTime()) / (1000 * 60 * 60 * 24));
                if (daysBetween > 0) {
                    width += daysBetween * this.parent.perDayWidth;
                }
                ranges = endException.hasException
                    ? endException.data.workingRange
                    : this.parent.workingTimeRanges;
                width += this.calculateDayWidth(ranges, ranges[0].from, this.parent.dataOperation['getSecondsInDecimal'](eDate), this.parent.perDayWidth);
            }
            return width;
        };
        return CalendarModule;
    }());
    exports.CalendarModule = CalendarModule;
});