@syncfusion/ej2-gantt 19.4.56 → 20.1.47-1460716
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1072 -1060
- package/README.md +75 -75
- package/dist/ej2-gantt.umd.min.js +1 -10
- package/dist/ej2-gantt.umd.min.js.map +1 -1
- package/dist/es6/ej2-gantt.es2015.js +274 -176
- package/dist/es6/ej2-gantt.es2015.js.map +1 -1
- package/dist/es6/ej2-gantt.es5.js +642 -534
- package/dist/es6/ej2-gantt.es5.js.map +1 -1
- package/dist/global/ej2-gantt.min.js +1 -10
- package/dist/global/ej2-gantt.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/components.ts +4 -0
- package/dist/ts/gantt/actions/actions.ts +18 -0
- package/dist/ts/gantt/actions/cell-edit.ts +606 -0
- package/dist/ts/gantt/actions/chart-scroll.ts +167 -0
- package/dist/ts/gantt/actions/column-menu.ts +35 -0
- package/dist/ts/gantt/actions/column-reorder.ts +52 -0
- package/dist/ts/gantt/actions/column-resize.ts +52 -0
- package/dist/ts/gantt/actions/connector-line-edit.ts +829 -0
- package/dist/ts/gantt/actions/context-menu.ts +754 -0
- package/dist/ts/gantt/actions/day-markers.ts +80 -0
- package/dist/ts/gantt/actions/dependency.ts +692 -0
- package/dist/ts/gantt/actions/dialog-edit.ts +2208 -0
- package/dist/ts/gantt/actions/edit.ts +3499 -0
- package/dist/ts/gantt/actions/excel-export.ts +61 -0
- package/dist/ts/gantt/actions/filter.ts +302 -0
- package/dist/ts/gantt/actions/keyboard.ts +306 -0
- package/dist/ts/gantt/actions/pdf-export.ts +214 -0
- package/dist/ts/gantt/actions/rowdragdrop.ts +839 -0
- package/dist/ts/gantt/actions/selection.ts +536 -0
- package/dist/ts/gantt/actions/sort.ts +98 -0
- package/dist/ts/gantt/actions/taskbar-edit.ts +1940 -0
- package/dist/ts/gantt/actions/toolbar.ts +489 -0
- package/dist/ts/gantt/actions/virtual-scroll.ts +60 -0
- package/dist/ts/gantt/base/common.ts +9 -0
- package/dist/ts/gantt/base/constant.ts +13 -0
- package/dist/ts/gantt/base/css-constants.ts +148 -0
- package/dist/ts/gantt/base/date-processor.ts +1257 -0
- package/dist/ts/gantt/base/enum.ts +372 -0
- package/dist/ts/gantt/base/gantt-chart.ts +1248 -0
- package/dist/ts/gantt/base/gantt.ts +4069 -0
- package/dist/ts/gantt/base/interface.ts +955 -0
- package/dist/ts/gantt/base/splitter.ts +174 -0
- package/dist/ts/gantt/base/task-processor.ts +2217 -0
- package/dist/ts/gantt/base/tree-grid.ts +694 -0
- package/dist/ts/gantt/base/utils.ts +208 -0
- package/dist/ts/gantt/export/export-helper.ts +552 -0
- package/dist/ts/gantt/export/pdf-base/dictionary.ts +152 -0
- package/dist/ts/gantt/export/pdf-base/pdf-borders.ts +277 -0
- package/dist/ts/gantt/export/pdf-base/pdf-grid-table.ts +901 -0
- package/dist/ts/gantt/export/pdf-base/pdf-style/gantt-theme.ts +131 -0
- package/dist/ts/gantt/export/pdf-base/pdf-style/style.ts +91 -0
- package/dist/ts/gantt/export/pdf-base/treegrid-layouter.ts +414 -0
- package/dist/ts/gantt/export/pdf-connector-line.ts +422 -0
- package/dist/ts/gantt/export/pdf-gantt.ts +282 -0
- package/dist/ts/gantt/export/pdf-taskbar.ts +395 -0
- package/dist/ts/gantt/export/pdf-timeline.ts +202 -0
- package/dist/ts/gantt/export/pdf-treegrid.ts +406 -0
- package/dist/ts/gantt/models/add-dialog-field-settings.ts +33 -0
- package/dist/ts/gantt/models/column.ts +464 -0
- package/dist/ts/gantt/models/day-working-time.ts +22 -0
- package/dist/ts/gantt/models/edit-dialog-field-settings.ts +33 -0
- package/dist/ts/gantt/models/edit-settings.ts +79 -0
- package/dist/ts/gantt/models/event-marker.ts +27 -0
- package/dist/ts/gantt/models/filter-settings.ts +53 -0
- package/dist/ts/gantt/models/holiday.ts +34 -0
- package/dist/ts/gantt/models/label-settings.ts +30 -0
- package/dist/ts/gantt/models/models.ts +36 -0
- package/dist/ts/gantt/models/resource-fields.ts +38 -0
- package/dist/ts/gantt/models/search-settings.ts +77 -0
- package/dist/ts/gantt/models/selection-settings.ts +56 -0
- package/dist/ts/gantt/models/sort-settings.ts +50 -0
- package/dist/ts/gantt/models/splitter-settings.ts +47 -0
- package/dist/ts/gantt/models/task-fields.ts +171 -0
- package/dist/ts/gantt/models/timeline-settings.ts +112 -0
- package/dist/ts/gantt/models/tooltip-settings.ts +46 -0
- package/dist/ts/gantt/renderer/chart-rows.ts +1838 -0
- package/dist/ts/gantt/renderer/connector-line.ts +1025 -0
- package/dist/ts/gantt/renderer/edit-tooltip.ts +228 -0
- package/dist/ts/gantt/renderer/event-marker.ts +96 -0
- package/dist/ts/gantt/renderer/nonworking-day.ts +205 -0
- package/dist/ts/gantt/renderer/render.ts +5 -0
- package/dist/ts/gantt/renderer/timeline.ts +1397 -0
- package/dist/ts/gantt/renderer/tooltip.ts +450 -0
- package/dist/ts/gantt/renderer/virtual-content-render.ts +50 -0
- package/license +9 -9
- package/package.json +80 -80
- package/src/gantt/actions/cell-edit.js +2 -1
- package/src/gantt/actions/dialog-edit.js +2 -1
- package/src/gantt/actions/edit.js +11 -2
- package/src/gantt/actions/rowdragdrop.js +37 -15
- package/src/gantt/actions/taskbar-edit.js +24 -24
- package/src/gantt/base/date-processor.js +0 -1
- package/src/gantt/base/gantt-chart.js +9 -4
- package/src/gantt/base/gantt-model.d.ts +779 -779
- package/src/gantt/base/gantt.d.ts +27 -27
- package/src/gantt/base/gantt.js +22 -22
- package/src/gantt/base/splitter.js +1 -0
- package/src/gantt/base/task-processor.js +13 -13
- package/src/gantt/base/tree-grid.js +3 -1
- package/src/gantt/export/pdf-base/treegrid-layouter.js +13 -13
- package/src/gantt/export/pdf-connector-line.js +11 -11
- package/src/gantt/export/pdf-gantt.js +24 -24
- package/src/gantt/export/pdf-taskbar.js +11 -11
- package/src/gantt/export/pdf-treegrid.js +13 -13
- package/src/gantt/models/add-dialog-field-settings-model.d.ts +21 -21
- package/src/gantt/models/add-dialog-field-settings.js +19 -19
- package/src/gantt/models/day-working-time-model.d.ts +11 -11
- package/src/gantt/models/day-working-time.js +19 -19
- package/src/gantt/models/edit-dialog-field-settings-model.d.ts +21 -21
- package/src/gantt/models/edit-dialog-field-settings.js +19 -19
- package/src/gantt/models/edit-settings-model.d.ts +50 -50
- package/src/gantt/models/edit-settings.js +19 -19
- package/src/gantt/models/event-marker-model.d.ts +16 -16
- package/src/gantt/models/event-marker.js +19 -19
- package/src/gantt/models/filter-settings-model.d.ts +34 -34
- package/src/gantt/models/filter-settings.js +19 -19
- package/src/gantt/models/holiday-model.d.ts +21 -21
- package/src/gantt/models/holiday.js +19 -19
- package/src/gantt/models/label-settings-model.d.ts +16 -16
- package/src/gantt/models/label-settings.js +19 -19
- package/src/gantt/models/resource-fields-model.d.ts +21 -21
- package/src/gantt/models/resource-fields.js +19 -19
- package/src/gantt/models/search-settings-model.d.ts +56 -56
- package/src/gantt/models/search-settings.js +19 -19
- package/src/gantt/models/selection-settings-model.d.ts +35 -35
- package/src/gantt/models/selection-settings.js +19 -19
- package/src/gantt/models/sort-settings-model.d.ts +24 -24
- package/src/gantt/models/sort-settings.js +19 -19
- package/src/gantt/models/splitter-settings-model.d.ts +30 -30
- package/src/gantt/models/splitter-settings.js +19 -19
- package/src/gantt/models/task-fields-model.d.ts +110 -110
- package/src/gantt/models/task-fields.js +19 -19
- package/src/gantt/models/timeline-settings-model.d.ts +71 -71
- package/src/gantt/models/timeline-settings.js +19 -19
- package/src/gantt/models/tooltip-settings-model.d.ts +26 -26
- package/src/gantt/models/tooltip-settings.js +19 -19
- package/src/gantt/renderer/chart-rows.js +49 -37
- package/src/gantt/renderer/connector-line.js +22 -18
- package/src/gantt/renderer/event-marker.js +1 -0
- package/src/gantt/renderer/nonworking-day.js +13 -6
- package/src/gantt/renderer/timeline.d.ts +1 -0
- package/src/gantt/renderer/timeline.js +48 -12
- package/src/gantt/renderer/tooltip.js +11 -3
- package/styles/bootstrap-dark.css +442 -427
- package/styles/bootstrap.css +442 -433
- package/styles/bootstrap4.css +454 -479
- package/styles/bootstrap5-dark.css +457 -433
- package/styles/bootstrap5.css +457 -433
- package/styles/fabric-dark.css +438 -421
- package/styles/fabric.css +445 -428
- package/styles/fluent-dark.css +1938 -0
- package/styles/fluent-dark.scss +1 -0
- package/styles/fluent.css +1938 -0
- package/styles/fluent.scss +1 -0
- package/styles/gantt/_all.scss +2 -2
- package/styles/gantt/_bootstrap-dark-definition.scss +210 -156
- package/styles/gantt/_bootstrap-definition.scss +211 -157
- package/styles/gantt/_bootstrap4-definition.scss +213 -158
- package/styles/gantt/_bootstrap5-definition.scss +215 -162
- package/styles/gantt/_fabric-dark-definition.scss +211 -157
- package/styles/gantt/_fabric-definition.scss +211 -157
- package/styles/gantt/_fluent-dark-definition.scss +1 -0
- package/styles/gantt/_fluent-definition.scss +215 -162
- package/styles/gantt/_fusionnew-definition.scss +214 -0
- package/styles/gantt/_highcontrast-definition.scss +211 -157
- package/styles/gantt/_highcontrast-light-definition.scss +211 -157
- package/styles/gantt/_layout.scss +1446 -1027
- package/styles/gantt/_material-dark-definition.scss +212 -157
- package/styles/gantt/_material-definition.scss +212 -157
- package/styles/gantt/_material3-definition.scss +215 -0
- package/styles/gantt/_tailwind-definition.scss +215 -161
- package/styles/gantt/_theme.scss +702 -668
- package/styles/gantt/bootstrap-dark.css +442 -427
- package/styles/gantt/bootstrap.css +442 -433
- package/styles/gantt/bootstrap4.css +454 -479
- package/styles/gantt/bootstrap5-dark.css +457 -433
- package/styles/gantt/bootstrap5.css +457 -433
- package/styles/gantt/fabric-dark.css +438 -421
- package/styles/gantt/fabric.css +445 -428
- package/styles/gantt/fluent-dark.css +1938 -0
- package/styles/gantt/fluent-dark.scss +22 -0
- package/styles/gantt/fluent.css +1938 -0
- package/styles/gantt/fluent.scss +22 -0
- package/styles/gantt/highcontrast-light.css +405 -405
- package/styles/gantt/highcontrast.css +444 -456
- package/styles/gantt/icons/_bootstrap-dark.scss +124 -113
- package/styles/gantt/icons/_bootstrap.scss +124 -113
- package/styles/gantt/icons/_bootstrap4.scss +124 -113
- package/styles/gantt/icons/_bootstrap5.scss +124 -112
- package/styles/gantt/icons/_fabric-dark.scss +124 -112
- package/styles/gantt/icons/_fabric.scss +124 -112
- package/styles/gantt/icons/_fluent-dark.scss +1 -0
- package/styles/gantt/icons/_fluent.scss +124 -112
- package/styles/gantt/icons/_fusionnew.scss +120 -0
- package/styles/gantt/icons/_highcontrast.scss +124 -112
- package/styles/gantt/icons/_material-dark.scss +124 -112
- package/styles/gantt/icons/_material.scss +124 -112
- package/styles/gantt/icons/_material3.scss +124 -0
- package/styles/gantt/icons/_tailwind-dark.scss +124 -113
- package/styles/gantt/icons/_tailwind.scss +124 -113
- package/styles/gantt/material-dark.css +446 -417
- package/styles/gantt/material.css +445 -419
- package/styles/gantt/tailwind-dark.css +452 -482
- package/styles/gantt/tailwind.css +449 -479
- package/styles/highcontrast-light.css +405 -405
- package/styles/highcontrast.css +444 -456
- package/styles/material-dark.css +446 -417
- package/styles/material.css +445 -419
- package/styles/tailwind-dark.css +452 -482
- package/styles/tailwind.css +449 -479
|
@@ -0,0 +1,1257 @@
|
|
|
1
|
+
import { isNullOrUndefined, getValue, setValue } from '@syncfusion/ej2-base';
|
|
2
|
+
import { IGanttData, IWorkingTimeRange, ITaskData, IIndicator, ITaskSegment } from './interface';
|
|
3
|
+
import { HolidayModel, DayWorkingTimeModel, EventMarkerModel } from '../models/models';
|
|
4
|
+
import { ColumnModel as GanttColumnModel } from '../models/column';
|
|
5
|
+
import { TextBox } from '@syncfusion/ej2-inputs';
|
|
6
|
+
interface EJ2Instance extends HTMLElement {
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line
|
|
9
|
+
ej2_instances: Object[];
|
|
10
|
+
}
|
|
11
|
+
import { Gantt } from './gantt';
|
|
12
|
+
/**
|
|
13
|
+
* Date processor is used to handle date of task data.
|
|
14
|
+
*/
|
|
15
|
+
export class DateProcessor {
|
|
16
|
+
protected parent: Gantt;
|
|
17
|
+
private prevProjectStartDate: Date;
|
|
18
|
+
constructor(parent: Gantt) {
|
|
19
|
+
this.parent = parent;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @param {ITaskData} ganttProp .
|
|
23
|
+
* @returns {boolean} .
|
|
24
|
+
*/
|
|
25
|
+
private isValidateNonWorkDays(ganttProp: ITaskData): boolean {
|
|
26
|
+
return (!isNullOrUndefined(ganttProp) && ganttProp.isAutoSchedule &&
|
|
27
|
+
(!this.parent.includeWeekend || this.parent.totalHolidayDates.length > 0)) ||
|
|
28
|
+
(isNullOrUndefined(ganttProp) && (!this.parent.includeWeekend || this.parent.totalHolidayDates.length > 0));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Method to convert given date value as valid start date
|
|
32
|
+
*
|
|
33
|
+
* @param {Date} date .
|
|
34
|
+
* @param {ITaskData} ganttProp .
|
|
35
|
+
* @param {boolean} validateAsMilestone .
|
|
36
|
+
* @param {boolean} isLoad .
|
|
37
|
+
* @returns {Date} .
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
public checkStartDate(date: Date, ganttProp?: ITaskData, validateAsMilestone?: boolean, isLoad?: boolean): Date {
|
|
41
|
+
if (isNullOrUndefined(date)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
let cloneStartDate: Date = new Date(date.getTime()); const hour: number = this.getSecondsInDecimal(cloneStartDate);
|
|
45
|
+
validateAsMilestone = isNullOrUndefined(validateAsMilestone) ? !isNullOrUndefined(ganttProp) ?
|
|
46
|
+
ganttProp.isMilestone : false : validateAsMilestone;
|
|
47
|
+
if (hour < this.parent.defaultStartTime && (!validateAsMilestone || isLoad)) {
|
|
48
|
+
this.setTime(this.parent.defaultStartTime, cloneStartDate);
|
|
49
|
+
} else if (hour < this.parent.defaultStartTime && validateAsMilestone) {
|
|
50
|
+
this.setTime(this.parent.defaultEndTime, cloneStartDate);
|
|
51
|
+
} else if ((hour === this.parent.defaultEndTime && (!ganttProp || !validateAsMilestone)) || hour > this.parent.defaultEndTime) {
|
|
52
|
+
cloneStartDate.setDate(cloneStartDate.getDate() + 1);
|
|
53
|
+
this.setTime(this.parent.defaultStartTime, cloneStartDate);
|
|
54
|
+
} else if (hour > this.parent.defaultStartTime && hour < this.parent.defaultEndTime) {
|
|
55
|
+
for (let index: number = 0; index < this.parent.workingTimeRanges.length; index++) {
|
|
56
|
+
const value: IWorkingTimeRange = this.parent.workingTimeRanges[index];
|
|
57
|
+
if (hour >= value.to && (this.parent.workingTimeRanges[index + 1] &&
|
|
58
|
+
hour < this.parent.workingTimeRanges[index + 1].from)) {
|
|
59
|
+
// milestone can fall at end any interval time
|
|
60
|
+
if ((hour === value.to && (!ganttProp || !validateAsMilestone)) || hour !== value.to) {
|
|
61
|
+
this.setTime(this.parent.workingTimeRanges[index + 1].from, cloneStartDate);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let tStartDate: Date;
|
|
68
|
+
do {
|
|
69
|
+
tStartDate = new Date(cloneStartDate.getTime());
|
|
70
|
+
const holidayLength: number = this.parent.totalHolidayDates.length;
|
|
71
|
+
// check holidays and weekends
|
|
72
|
+
if (this.isValidateNonWorkDays(ganttProp)) {
|
|
73
|
+
const startTime: number = (!validateAsMilestone || isLoad) ? this.parent.defaultStartTime : this.parent.defaultEndTime;
|
|
74
|
+
if (!this.parent.includeWeekend) {
|
|
75
|
+
const tempDate: Date = new Date(cloneStartDate.getTime());
|
|
76
|
+
cloneStartDate = this.getNextWorkingDay(cloneStartDate);
|
|
77
|
+
if (tempDate.getTime() !== cloneStartDate.getTime()) {
|
|
78
|
+
this.setTime(startTime, cloneStartDate);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (let count: number = 0; count < holidayLength; count++) {
|
|
82
|
+
const holidayFrom: Date = this.getDateFromFormat(new Date(this.parent.totalHolidayDates[count]));
|
|
83
|
+
const holidayTo: Date = new Date(holidayFrom.getTime());
|
|
84
|
+
holidayFrom.setHours(0, 0, 0, 0);
|
|
85
|
+
holidayTo.setHours(23, 59, 59, 59);
|
|
86
|
+
if (cloneStartDate.getTime() >= holidayFrom.getTime() && cloneStartDate.getTime() < holidayTo.getTime()) {
|
|
87
|
+
cloneStartDate.setDate(cloneStartDate.getDate() + 1);
|
|
88
|
+
this.setTime(startTime, cloneStartDate);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} while (tStartDate.getTime() !== cloneStartDate.getTime());
|
|
93
|
+
return new Date(cloneStartDate.getTime());
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* To update given date value to valid end date
|
|
97
|
+
*
|
|
98
|
+
* @param {Date} date .
|
|
99
|
+
* @param {ITaskData} ganttProp .
|
|
100
|
+
* @param {boolean} validateAsMilestone .
|
|
101
|
+
* @returns {Date} .
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
public checkEndDate(date: Date, ganttProp?: ITaskData, validateAsMilestone?: boolean): Date {
|
|
105
|
+
if (isNullOrUndefined(date)) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
let cloneEndDate: Date = new Date(date.getTime());
|
|
109
|
+
const hour: number = this.getSecondsInDecimal(cloneEndDate);
|
|
110
|
+
if (hour > this.parent.defaultEndTime) {
|
|
111
|
+
this.setTime(this.parent.defaultEndTime, cloneEndDate);
|
|
112
|
+
} else if (hour <= this.parent.defaultStartTime && !validateAsMilestone) {
|
|
113
|
+
cloneEndDate.setDate(cloneEndDate.getDate() - 1);
|
|
114
|
+
this.setTime(this.parent.defaultEndTime, cloneEndDate);
|
|
115
|
+
} else if (hour > this.parent.defaultStartTime && hour < this.parent.defaultEndTime) {
|
|
116
|
+
for (let index: number = 0; index < this.parent.workingTimeRanges.length; index++) {
|
|
117
|
+
const value: IWorkingTimeRange = this.parent.workingTimeRanges[index];
|
|
118
|
+
if (hour > value.to && (this.parent.workingTimeRanges[index + 1] &&
|
|
119
|
+
hour <= this.parent.workingTimeRanges[index + 1].from)) {
|
|
120
|
+
this.setTime(this.parent.workingTimeRanges[index].to, cloneEndDate);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
let tempCheckDate: Date;
|
|
126
|
+
do {
|
|
127
|
+
tempCheckDate = new Date(cloneEndDate.getTime());
|
|
128
|
+
const holidayLength: number = this.parent.totalHolidayDates.length;
|
|
129
|
+
if (this.isValidateNonWorkDays(ganttProp)) {
|
|
130
|
+
if (!this.parent.includeWeekend) {
|
|
131
|
+
const tempDate: Date = new Date(cloneEndDate.getTime());
|
|
132
|
+
cloneEndDate = this.getPreviousWorkingDay(cloneEndDate);
|
|
133
|
+
if (tempDate.getTime() !== cloneEndDate.getTime()) {
|
|
134
|
+
this.setTime(this.parent.defaultEndTime, cloneEndDate);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (let count: number = 0; count < holidayLength; count++) {
|
|
138
|
+
const holidayFrom: Date = this.getDateFromFormat(new Date(this.parent.totalHolidayDates[count]));
|
|
139
|
+
const holidayTo: Date = new Date(holidayFrom.getTime());
|
|
140
|
+
const tempHoliday: Date = new Date(cloneEndDate.getTime());
|
|
141
|
+
tempHoliday.setMinutes(cloneEndDate.getMilliseconds() - 2);
|
|
142
|
+
holidayFrom.setHours(0, 0, 0, 0);
|
|
143
|
+
holidayTo.setHours(23, 59, 59, 59);
|
|
144
|
+
if (cloneEndDate.getTime() >= holidayFrom.getTime() && cloneEndDate.getTime() < holidayTo.getTime() ||
|
|
145
|
+
tempHoliday.getTime() >= holidayFrom.getTime() && tempHoliday.getTime() < holidayTo.getTime()) {
|
|
146
|
+
cloneEndDate.setDate(cloneEndDate.getDate() - 1);
|
|
147
|
+
if (!(cloneEndDate.getTime() === holidayFrom.getTime() && this.parent.defaultEndTime === 86400 &&
|
|
148
|
+
this.getSecondsInDecimal(cloneEndDate) === 0)) {
|
|
149
|
+
this.setTime(this.parent.defaultEndTime, cloneEndDate);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} while (tempCheckDate.getTime() !== cloneEndDate.getTime());
|
|
155
|
+
return new Date(cloneEndDate.getTime());
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* To validate the baseline start date
|
|
159
|
+
*
|
|
160
|
+
* @param {Date} date .
|
|
161
|
+
* @returns {Date} .
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
public checkBaselineStartDate(date: Date): Date {
|
|
165
|
+
if (isNullOrUndefined(date)) {
|
|
166
|
+
return null;
|
|
167
|
+
} else {
|
|
168
|
+
const cloneDate: Date = new Date(date.getTime()); const hour: number = this.getSecondsInDecimal(cloneDate);
|
|
169
|
+
if (hour < this.parent.defaultStartTime) {
|
|
170
|
+
this.setTime(this.parent.defaultStartTime, cloneDate);
|
|
171
|
+
} else if (hour >= this.parent.defaultEndTime) {
|
|
172
|
+
cloneDate.setDate(cloneDate.getDate() + 1);
|
|
173
|
+
this.setTime(this.parent.defaultStartTime, cloneDate);
|
|
174
|
+
} else if (hour > this.parent.defaultStartTime && hour < this.parent.defaultEndTime) {
|
|
175
|
+
for (let i: number = 0; i < this.parent.workingTimeRanges.length; i++) {
|
|
176
|
+
const value: IWorkingTimeRange = this.parent.workingTimeRanges[i];
|
|
177
|
+
if (hour >= value.to && (this.parent.workingTimeRanges[i + 1] &&
|
|
178
|
+
hour < this.parent.workingTimeRanges[i + 1].from)) {
|
|
179
|
+
this.setTime(this.parent.workingTimeRanges[i + 1].from, cloneDate);
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return cloneDate;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* To validate baseline end date
|
|
189
|
+
*
|
|
190
|
+
* @param {Date} date .
|
|
191
|
+
* @returns {Date} .
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
public checkBaselineEndDate(date: Date): Date {
|
|
195
|
+
if (isNullOrUndefined(date)) {
|
|
196
|
+
return null;
|
|
197
|
+
} else {
|
|
198
|
+
const cloneDate: Date = new Date(date.getTime()); const hour: number = this.getSecondsInDecimal(cloneDate);
|
|
199
|
+
if (hour > this.parent.defaultEndTime) {
|
|
200
|
+
this.setTime(this.parent.defaultEndTime, cloneDate);
|
|
201
|
+
} else if (hour <= this.parent.defaultStartTime) {
|
|
202
|
+
cloneDate.setDate(cloneDate.getDate() - 1);
|
|
203
|
+
this.setTime(this.parent.defaultEndTime, cloneDate);
|
|
204
|
+
} else if (hour > this.parent.defaultStartTime && hour < this.parent.defaultEndTime) {
|
|
205
|
+
for (let i: number = 0; i < this.parent.workingTimeRanges.length; i++) {
|
|
206
|
+
const value: IWorkingTimeRange = this.parent.workingTimeRanges[i];
|
|
207
|
+
if (hour > value.to && (this.parent.workingTimeRanges[i + 1] && hour <= this.parent.workingTimeRanges[i + 1].from)) {
|
|
208
|
+
this.setTime(this.parent.workingTimeRanges[i].to, cloneDate);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return cloneDate;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* To calculate start date value from duration and end date
|
|
218
|
+
*
|
|
219
|
+
* @param {IGanttData} ganttData - Defines the gantt data.
|
|
220
|
+
* @returns {void} .
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
public calculateStartDate(ganttData: IGanttData): void {
|
|
224
|
+
const ganttProp: ITaskData = ganttData.ganttProperties;
|
|
225
|
+
let tempStartDate: Date = null;
|
|
226
|
+
if (!isNullOrUndefined(ganttProp.endDate) && !isNullOrUndefined(ganttProp.duration)) {
|
|
227
|
+
tempStartDate = this.getStartDate(ganttProp.endDate, ganttProp.duration, ganttProp.durationUnit, ganttProp);
|
|
228
|
+
}
|
|
229
|
+
this.parent.setRecordValue('startDate', tempStartDate, ganttProp, true);
|
|
230
|
+
if (this.parent.taskFields.startDate) {
|
|
231
|
+
this.parent.dataOperation.updateMappingData(ganttData, 'startDate');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
*
|
|
236
|
+
* @param {IGanttData} ganttData - Defines the gantt data.
|
|
237
|
+
* @returns {void} .
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
public calculateEndDate(ganttData: IGanttData): void {
|
|
241
|
+
const ganttProp: ITaskData = ganttData.ganttProperties;
|
|
242
|
+
let tempEndDate: Date = null;
|
|
243
|
+
if (!isNullOrUndefined(ganttProp.startDate)) {
|
|
244
|
+
if (!isNullOrUndefined(ganttProp.endDate) && isNullOrUndefined(ganttProp.duration)) {
|
|
245
|
+
if (this.compareDates(ganttProp.startDate, ganttProp.endDate) === 1) {
|
|
246
|
+
this.parent.setRecordValue('startDate', new Date(ganttProp.endDate.getTime()), ganttProp, true);
|
|
247
|
+
this.setTime(this.parent.defaultStartTime, ganttProp.startDate);
|
|
248
|
+
}
|
|
249
|
+
this.calculateDuration(ganttData);
|
|
250
|
+
}
|
|
251
|
+
if (!isNullOrUndefined(ganttProp.duration)) {
|
|
252
|
+
const duration: number = !isNullOrUndefined(ganttProp.segments) && ganttProp.segments.length > 0 ?
|
|
253
|
+
this.totalDuration(ganttProp.segments) : ganttProp.duration;
|
|
254
|
+
tempEndDate = this.getEndDate(ganttProp.startDate, duration, ganttProp.durationUnit, ganttProp, false);
|
|
255
|
+
}
|
|
256
|
+
this.parent.setRecordValue('endDate', tempEndDate, ganttProp, true);
|
|
257
|
+
}
|
|
258
|
+
if (this.parent.taskFields.endDate) {
|
|
259
|
+
this.parent.dataOperation.updateMappingData(ganttData, 'endDate');
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public totalDuration(segments: ITaskSegment[]): number {
|
|
264
|
+
let duration: number = 0;
|
|
265
|
+
for (let i: number = 0; i < segments.length; i++) {
|
|
266
|
+
duration += segments[i].duration + segments[i].offsetDuration;
|
|
267
|
+
}
|
|
268
|
+
return duration;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* To calculate duration from start date and end date
|
|
272
|
+
*
|
|
273
|
+
* @param {IGanttData} ganttData - Defines the gantt data.
|
|
274
|
+
* @returns {void} .
|
|
275
|
+
*/
|
|
276
|
+
public calculateDuration(ganttData: IGanttData): void {
|
|
277
|
+
const ganttProperties: ITaskData = ganttData.ganttProperties;
|
|
278
|
+
let tDuration: number;
|
|
279
|
+
if (!isNullOrUndefined(ganttProperties.segments) && ganttProperties.segments.length > 0 &&
|
|
280
|
+
!isNullOrUndefined(this.parent.editModule.taskbarEditModule)) {
|
|
281
|
+
tDuration = this.parent.editModule.taskbarEditModule.sumOfDuration(ganttProperties.segments);
|
|
282
|
+
} else {
|
|
283
|
+
if (!isNullOrUndefined(ganttProperties.startDate) && !isNullOrUndefined(ganttProperties.endDate) &&
|
|
284
|
+
(ganttProperties.startDate).getTime() === (ganttProperties.endDate).getTime() && !isNullOrUndefined(ganttData.taskData[this.parent.taskFields.milestone])) {
|
|
285
|
+
tDuration = 1;
|
|
286
|
+
} else {
|
|
287
|
+
tDuration = this.getDuration(
|
|
288
|
+
ganttProperties.startDate, ganttProperties.endDate, ganttProperties.durationUnit,
|
|
289
|
+
ganttProperties.isAutoSchedule, ganttProperties.isMilestone);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
this.parent.setRecordValue('duration', tDuration, ganttProperties, true);
|
|
293
|
+
const col: GanttColumnModel = this.parent.columnByField[this.parent.columnMapping.duration];
|
|
294
|
+
if (!isNullOrUndefined(this.parent.editModule) && !isNullOrUndefined(this.parent.editModule.cellEditModule) &&
|
|
295
|
+
!this.parent.editModule.cellEditModule.isCellEdit && !isNullOrUndefined(col)) {
|
|
296
|
+
if (!isNullOrUndefined(col.edit) && !isNullOrUndefined(col.edit.read)) {
|
|
297
|
+
const dialog: HTMLElement = this.parent.editModule.dialogModule.dialog;
|
|
298
|
+
if (!isNullOrUndefined(dialog)) {
|
|
299
|
+
const textBox: TextBox = <TextBox>(<EJ2Instance>dialog.querySelector('#' + this.parent.element.id + 'Duration'))
|
|
300
|
+
.ej2_instances[0];
|
|
301
|
+
if (!isNullOrUndefined(textBox) && textBox.value !== tDuration.toString()) {
|
|
302
|
+
textBox.value = tDuration.toString();
|
|
303
|
+
textBox.dataBind();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (this.parent.taskFields.duration) {
|
|
308
|
+
this.parent.dataOperation.updateMappingData(ganttData, 'duration');
|
|
309
|
+
if (this.parent.taskFields.durationUnit) {
|
|
310
|
+
this.parent.dataOperation.updateMappingData(ganttData, 'durationUnit');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @param {Date} sDate Method to get total nonworking time between two date values
|
|
318
|
+
* @param {Date} eDate .
|
|
319
|
+
* @param {boolean} isAutoSchedule .
|
|
320
|
+
* @param {boolean} isCheckTimeZone .
|
|
321
|
+
* @returns {number} .
|
|
322
|
+
*/
|
|
323
|
+
private getNonworkingTime(sDate: Date, eDate: Date, isAutoSchedule: boolean, isCheckTimeZone: boolean): number {
|
|
324
|
+
isCheckTimeZone = isNullOrUndefined(isCheckTimeZone) ? true : isCheckTimeZone;
|
|
325
|
+
const weekendCount: number = !this.parent.includeWeekend && isAutoSchedule ? this.getWeekendCount(sDate, eDate) : 0;
|
|
326
|
+
const totalHours: number = this.getNumberOfSeconds(sDate, eDate, isCheckTimeZone);
|
|
327
|
+
const holidaysCount: number = isAutoSchedule ? this.getHolidaysCount(sDate, eDate) : 0;
|
|
328
|
+
const totWorkDays: number = (totalHours - (weekendCount * 86400) - (holidaysCount * 86400)) / 86400; // working days between two dates
|
|
329
|
+
const nonWorkHours: number = this.getNonWorkingSecondsOnDate(sDate, eDate, isAutoSchedule);
|
|
330
|
+
const totalNonWorkTime: number = (totWorkDays * (86400 - this.parent.secondsPerDay)) +
|
|
331
|
+
(weekendCount * 86400) + (holidaysCount * 86400) + nonWorkHours;
|
|
332
|
+
return totalNonWorkTime;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* @param {Date} startDate .
|
|
338
|
+
* @param {Date} endDate .
|
|
339
|
+
* @param {string} durationUnit .
|
|
340
|
+
* @param {boolean} isAutoSchedule .
|
|
341
|
+
* @param {boolean} isMilestone .
|
|
342
|
+
* @param {boolean} isCheckTimeZone .
|
|
343
|
+
* @returns {number} .
|
|
344
|
+
* @private
|
|
345
|
+
*/
|
|
346
|
+
public getDuration(
|
|
347
|
+
startDate: Date, endDate: Date, durationUnit: string, isAutoSchedule: boolean,
|
|
348
|
+
isMilestone: boolean, isCheckTimeZone?: boolean): number {
|
|
349
|
+
if (isNullOrUndefined(startDate) || isNullOrUndefined(endDate)) {
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
isCheckTimeZone = isNullOrUndefined(isCheckTimeZone) ? true : isCheckTimeZone;
|
|
353
|
+
let durationValue: number = 0;
|
|
354
|
+
const timeDiff: number = this.getTimeDifference(startDate, endDate, isCheckTimeZone) / 1000;
|
|
355
|
+
const nonWorkHours: number = this.getNonworkingTime(startDate, endDate, isAutoSchedule, isCheckTimeZone);
|
|
356
|
+
const durationHours: number = timeDiff - nonWorkHours;
|
|
357
|
+
if (isMilestone && this.parent.getFormatedDate(startDate) === this.parent.getFormatedDate(endDate)) {
|
|
358
|
+
durationValue = 0;
|
|
359
|
+
} else {
|
|
360
|
+
if (!durationUnit || durationUnit === 'day') {
|
|
361
|
+
durationValue = durationHours / this.parent.secondsPerDay;
|
|
362
|
+
} else if (durationUnit === 'minute') {
|
|
363
|
+
durationValue = durationHours / 60;
|
|
364
|
+
} else {
|
|
365
|
+
durationValue = durationHours / 3600;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return parseFloat(durationValue.toString());
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
*
|
|
372
|
+
* @param {number} duration .
|
|
373
|
+
* @param {string} durationUnit .
|
|
374
|
+
* @returns {number} .
|
|
375
|
+
*/
|
|
376
|
+
private getDurationAsSeconds(duration: number, durationUnit: string): number {
|
|
377
|
+
let value: number = 0;
|
|
378
|
+
if (!durationUnit || durationUnit === 'day') {
|
|
379
|
+
value = this.parent.secondsPerDay * duration;
|
|
380
|
+
} else if (durationUnit === 'hour') {
|
|
381
|
+
value = duration * 3600;
|
|
382
|
+
} else {
|
|
383
|
+
value = duration * 60;
|
|
384
|
+
}
|
|
385
|
+
return value;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* To get date from start date and duration
|
|
389
|
+
*
|
|
390
|
+
* @param {Date} startDate .
|
|
391
|
+
* @param {number} duration .
|
|
392
|
+
* @param {string} durationUnit .
|
|
393
|
+
* @param {ITaskData} ganttProp .
|
|
394
|
+
* @param {boolean} validateAsMilestone .
|
|
395
|
+
* @returns {Date} .
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
public getEndDate(
|
|
399
|
+
startDate: Date, duration: number, durationUnit: string, ganttProp: ITaskData, validateAsMilestone: boolean): Date {
|
|
400
|
+
let tempStart: Date = new Date(startDate.getTime());
|
|
401
|
+
let endDate: Date = new Date(startDate.getTime());
|
|
402
|
+
let secondDuration: number = this.getDurationAsSeconds(duration, durationUnit);
|
|
403
|
+
let nonWork: number = 0;
|
|
404
|
+
let workHours: number = 0;
|
|
405
|
+
while (secondDuration > 0) {
|
|
406
|
+
endDate.setSeconds(endDate.getSeconds() + secondDuration);
|
|
407
|
+
nonWork = this.getNonworkingTime(tempStart, endDate, ganttProp.isAutoSchedule, true);
|
|
408
|
+
workHours = secondDuration - nonWork;
|
|
409
|
+
secondDuration = secondDuration - workHours;
|
|
410
|
+
if (secondDuration > 0) {
|
|
411
|
+
endDate = this.checkStartDate(endDate, ganttProp, validateAsMilestone);
|
|
412
|
+
}
|
|
413
|
+
tempStart = new Date(endDate.getTime());
|
|
414
|
+
}
|
|
415
|
+
return endDate;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
*
|
|
419
|
+
* @param {Date} endDate To calculate start date vale from end date and duration
|
|
420
|
+
* @param {number} duration .
|
|
421
|
+
* @param {string} durationUnit .
|
|
422
|
+
* @param {ITaskData} ganttProp .
|
|
423
|
+
* @returns {Date} .
|
|
424
|
+
* @private
|
|
425
|
+
*/
|
|
426
|
+
public getStartDate(endDate: Date, duration: number, durationUnit: string, ganttProp: ITaskData): Date {
|
|
427
|
+
let tempEnd: Date = new Date(endDate.getTime());
|
|
428
|
+
const startDate: Date = new Date(endDate.getTime());
|
|
429
|
+
let secondDuration: number = this.getDurationAsSeconds(duration, durationUnit);
|
|
430
|
+
let nonWork: number = 0;
|
|
431
|
+
let workHours: number = 0;
|
|
432
|
+
while (secondDuration > 0) {
|
|
433
|
+
startDate.setSeconds(startDate.getSeconds() - secondDuration);
|
|
434
|
+
nonWork = this.getNonworkingTime(startDate, tempEnd, ganttProp.isAutoSchedule, true);
|
|
435
|
+
workHours = secondDuration - nonWork;
|
|
436
|
+
secondDuration = secondDuration - workHours;
|
|
437
|
+
if (secondDuration > 0) {
|
|
438
|
+
tempEnd = this.checkEndDate(startDate, ganttProp);
|
|
439
|
+
}
|
|
440
|
+
tempEnd = new Date(startDate.getTime());
|
|
441
|
+
}
|
|
442
|
+
return startDate;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* @param {ITaskData} ganttProp .
|
|
447
|
+
* @param {boolean} isLoad .
|
|
448
|
+
* @returns {Date} .
|
|
449
|
+
* @private
|
|
450
|
+
*/
|
|
451
|
+
protected getProjectStartDate(ganttProp: ITaskData, isLoad?: boolean): Date {
|
|
452
|
+
|
|
453
|
+
if (!isNullOrUndefined(this.parent.cloneProjectStartDate)) {
|
|
454
|
+
const cloneStartDate: Date = this.checkStartDate(this.parent.cloneProjectStartDate);
|
|
455
|
+
this.parent.cloneProjectStartDate = cloneStartDate;
|
|
456
|
+
return new Date(cloneStartDate.getTime());
|
|
457
|
+
} else if (!isNullOrUndefined(this.parent.projectStartDate)) {
|
|
458
|
+
const cloneStartDate: Date = this.getDateFromFormat(this.parent.projectStartDate);
|
|
459
|
+
this.parent.cloneProjectStartDate = this.checkStartDate(cloneStartDate);
|
|
460
|
+
} else if (!isNullOrUndefined(isLoad)) {
|
|
461
|
+
const flatData: IGanttData[] = this.parent.flatData;
|
|
462
|
+
let minStartDate: Date;
|
|
463
|
+
if (flatData.length > 0) {
|
|
464
|
+
minStartDate = flatData[0].ganttProperties.startDate;
|
|
465
|
+
} else {
|
|
466
|
+
minStartDate = new Date();
|
|
467
|
+
minStartDate.setHours(0, 0, 0, 0);
|
|
468
|
+
}
|
|
469
|
+
for (let index: number = 1; index < flatData.length; index++) {
|
|
470
|
+
const startDate: Date = flatData[index].ganttProperties.startDate;
|
|
471
|
+
if (!isNullOrUndefined(startDate) && this.compareDates(startDate, minStartDate) === -1) {
|
|
472
|
+
minStartDate = startDate;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
this.parent.cloneProjectStartDate = this.checkStartDate(minStartDate, ganttProp);
|
|
476
|
+
} else {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
return new Date(this.parent.cloneProjectStartDate.getTime());
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* @param {ITaskData} ganttProp .
|
|
483
|
+
* @param {boolean} isAuto .
|
|
484
|
+
* @returns {Date} .
|
|
485
|
+
* @private
|
|
486
|
+
*/
|
|
487
|
+
public getValidStartDate(ganttProp: ITaskData, isAuto?: boolean): Date {
|
|
488
|
+
let sDate: Date = null;
|
|
489
|
+
const startDate: Date = isAuto ? ganttProp.autoStartDate : ganttProp.startDate;
|
|
490
|
+
const endDate: Date = isAuto ? ganttProp.autoEndDate : ganttProp.endDate;
|
|
491
|
+
const duration: number = !ganttProp.isAutoSchedule && ganttProp.autoDuration ? ganttProp.autoDuration : ganttProp.duration;
|
|
492
|
+
if (isNullOrUndefined(startDate)) {
|
|
493
|
+
if (!isNullOrUndefined(endDate)) {
|
|
494
|
+
sDate = new Date(endDate.getTime());
|
|
495
|
+
this.setTime(this.parent.defaultStartTime, sDate);
|
|
496
|
+
} else if (!isNullOrUndefined(duration)) {
|
|
497
|
+
sDate = this.getProjectStartDate(ganttProp);
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
sDate = new Date(startDate.getTime());
|
|
501
|
+
}
|
|
502
|
+
return sDate;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
*
|
|
506
|
+
* @param {ITaskData} ganttProp .
|
|
507
|
+
* @param {boolean} isAuto .
|
|
508
|
+
* @returns {Date} .
|
|
509
|
+
* @private
|
|
510
|
+
*/
|
|
511
|
+
public getValidEndDate(ganttProp: ITaskData, isAuto?: boolean): Date {
|
|
512
|
+
let eDate: Date = null;
|
|
513
|
+
const startDate: Date = isAuto ? ganttProp.autoStartDate : ganttProp.startDate;
|
|
514
|
+
const endDate: Date = isAuto ? ganttProp.autoEndDate : ganttProp.endDate;
|
|
515
|
+
const duration: number = isAuto ? ganttProp.autoDuration : ganttProp.duration;
|
|
516
|
+
if (isNullOrUndefined(endDate)) {
|
|
517
|
+
if (!isNullOrUndefined(startDate)) {
|
|
518
|
+
if (ganttProp.isMilestone) {
|
|
519
|
+
eDate = this.checkStartDate(startDate);
|
|
520
|
+
} else {
|
|
521
|
+
eDate = new Date(startDate.getTime());
|
|
522
|
+
this.setTime(this.parent.defaultEndTime, eDate);
|
|
523
|
+
}
|
|
524
|
+
} else if (!isNullOrUndefined(duration)) {
|
|
525
|
+
const sDate: Date = this.getValidStartDate(ganttProp);
|
|
526
|
+
if (sDate) {
|
|
527
|
+
eDate = this.getEndDate(sDate, duration, ganttProp.durationUnit, ganttProp, false);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
eDate = new Date(endDate.getTime());
|
|
532
|
+
}
|
|
533
|
+
return eDate;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* @returns {number} .
|
|
537
|
+
* @private
|
|
538
|
+
*/
|
|
539
|
+
public getSecondsPerDay(): number {
|
|
540
|
+
const dayWorkingTime: DayWorkingTimeModel[] = this.parent.dayWorkingTime;
|
|
541
|
+
const length: number = dayWorkingTime.length;
|
|
542
|
+
let totalSeconds: number = 0; const startDate: Date = new Date('10/11/2018');
|
|
543
|
+
this.parent.nonWorkingHours = [];
|
|
544
|
+
const nonWorkingHours: number[] = this.parent.nonWorkingHours;
|
|
545
|
+
this.parent.workingTimeRanges = [];
|
|
546
|
+
const workingTimeRanges: IWorkingTimeRange[] = this.parent.workingTimeRanges;
|
|
547
|
+
this.parent.nonWorkingTimeRanges = [];
|
|
548
|
+
const nonWorkingTimeRanges: IWorkingTimeRange[] = this.parent.nonWorkingTimeRanges;
|
|
549
|
+
|
|
550
|
+
for (let count: number = 0; count < length; count++) {
|
|
551
|
+
const currentRange: DayWorkingTimeModel = dayWorkingTime[count];
|
|
552
|
+
if (!isNullOrUndefined(currentRange.from) && !isNullOrUndefined(currentRange.to)) {
|
|
553
|
+
startDate.setHours(0, 0, 0, 0);
|
|
554
|
+
const tempDate: Date = new Date(startDate.getTime());
|
|
555
|
+
startDate.setTime(startDate.getTime() + (currentRange.from * 3600000));
|
|
556
|
+
const startHour: Date = new Date(startDate.getTime());
|
|
557
|
+
tempDate.setTime(tempDate.getTime() + (currentRange.to * 3600000));
|
|
558
|
+
const endHour: Date = new Date(tempDate.getTime());
|
|
559
|
+
const timeDiff: number = endHour.getTime() - startHour.getTime();
|
|
560
|
+
const sdSeconds: number = this.getSecondsInDecimal(startHour);
|
|
561
|
+
let edSeconds: number = this.getSecondsInDecimal(endHour);
|
|
562
|
+
if (edSeconds === 0) {
|
|
563
|
+
edSeconds = 86400;
|
|
564
|
+
}
|
|
565
|
+
totalSeconds += timeDiff / 1000;
|
|
566
|
+
if (count === 0) {
|
|
567
|
+
this.parent.defaultStartTime = sdSeconds;
|
|
568
|
+
}
|
|
569
|
+
if (count === length - 1) {
|
|
570
|
+
this.parent.defaultEndTime = edSeconds;
|
|
571
|
+
}
|
|
572
|
+
if (count > 0) {
|
|
573
|
+
nonWorkingHours.push(nonWorkingHours[nonWorkingHours.length - 1] +
|
|
574
|
+
sdSeconds - workingTimeRanges[count - 1].to);
|
|
575
|
+
if (workingTimeRanges[count - 1].to < sdSeconds) {
|
|
576
|
+
nonWorkingTimeRanges.push({
|
|
577
|
+
from: workingTimeRanges[count - 1].to, to: sdSeconds, isWorking: false,
|
|
578
|
+
interval: (sdSeconds - workingTimeRanges[count - 1].to)
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
nonWorkingHours.push(0);
|
|
583
|
+
nonWorkingTimeRanges.push({ from: 0, to: sdSeconds, isWorking: false, interval: sdSeconds });
|
|
584
|
+
}
|
|
585
|
+
workingTimeRanges.push({ from: sdSeconds, to: edSeconds });
|
|
586
|
+
nonWorkingTimeRanges.push({
|
|
587
|
+
from: sdSeconds, to: edSeconds, isWorking: true, interval: (edSeconds - sdSeconds)
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (this.parent.defaultEndTime / 3600 !== 24) {
|
|
592
|
+
nonWorkingTimeRanges.push({
|
|
593
|
+
from: this.parent.defaultEndTime, to: 86400,
|
|
594
|
+
isWorking: false, interval: 86400 - this.parent.defaultEndTime
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
return totalSeconds;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
*
|
|
601
|
+
* @param {string} value .
|
|
602
|
+
* @param {boolean} isFromDialog .
|
|
603
|
+
* @returns {object} .
|
|
604
|
+
* @private
|
|
605
|
+
*/
|
|
606
|
+
// eslint-disable-next-line
|
|
607
|
+
public getDurationValue(value: string | number, isFromDialog?: boolean): Object {
|
|
608
|
+
let durationUnit: string = null;
|
|
609
|
+
let duration: number = null;
|
|
610
|
+
|
|
611
|
+
if (typeof value === 'string') {
|
|
612
|
+
const values: Object[] = value.match(/(\d*\.*\d+|.+$)/g);
|
|
613
|
+
if (values && values.length <= 2) {
|
|
614
|
+
duration = parseFloat(values[0].toString().trim());
|
|
615
|
+
const unit: string = values[1] ? values[1].toString().trim().toLowerCase() : null;
|
|
616
|
+
if (getValue('minute', this.parent.durationUnitEditText).indexOf(unit) !== -1) {
|
|
617
|
+
durationUnit = 'minute';
|
|
618
|
+
} else if (getValue('hour', this.parent.durationUnitEditText).indexOf(unit) !== -1) {
|
|
619
|
+
durationUnit = 'hour';
|
|
620
|
+
} else if (getValue('day', this.parent.durationUnitEditText).indexOf(unit) !== -1) {
|
|
621
|
+
durationUnit = 'day';
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
duration = value;
|
|
626
|
+
durationUnit = null;
|
|
627
|
+
}
|
|
628
|
+
const output: Object = {
|
|
629
|
+
duration: duration,
|
|
630
|
+
durationUnit: durationUnit
|
|
631
|
+
};
|
|
632
|
+
return output;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
*
|
|
636
|
+
* @param {Date} date .
|
|
637
|
+
* @returns {Date} .
|
|
638
|
+
*/
|
|
639
|
+
protected getNextWorkingDay(date: Date): Date {
|
|
640
|
+
const dayIndex: number = date.getDay();
|
|
641
|
+
if (this.parent.nonWorkingDayIndex.indexOf(dayIndex) !== -1) {
|
|
642
|
+
date.setDate(date.getDate() + 1);
|
|
643
|
+
date = this.getNextWorkingDay(date);
|
|
644
|
+
return date;
|
|
645
|
+
} else {
|
|
646
|
+
return date;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* get weekend days between two dates without including args dates
|
|
651
|
+
*
|
|
652
|
+
* @param {Date} startDate .
|
|
653
|
+
* @param {Date} endDate .
|
|
654
|
+
* @returns {number} .
|
|
655
|
+
*/
|
|
656
|
+
protected getWeekendCount(startDate: Date, endDate: Date): number {
|
|
657
|
+
let weekendCount: number = 0;
|
|
658
|
+
const sDate: Date = new Date(startDate.getTime()); const eDate: Date = new Date(endDate.getTime());
|
|
659
|
+
sDate.setHours(0, 0, 0, 0);
|
|
660
|
+
sDate.setDate(sDate.getDate() + 1);
|
|
661
|
+
eDate.setHours(0, 0, 0, 0);
|
|
662
|
+
while (sDate.getTime() < eDate.getTime()) {
|
|
663
|
+
if (this.parent.nonWorkingDayIndex.indexOf(sDate.getDay()) !== -1) {
|
|
664
|
+
weekendCount += 1;
|
|
665
|
+
}
|
|
666
|
+
sDate.setDate(sDate.getDate() + 1);
|
|
667
|
+
}
|
|
668
|
+
return weekendCount;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
*
|
|
672
|
+
* @param {Date} startDate .
|
|
673
|
+
* @param {Date} endDate .
|
|
674
|
+
* @param {boolean} isCheckTimeZone .
|
|
675
|
+
* @returns {number} .
|
|
676
|
+
*/
|
|
677
|
+
protected getNumberOfSeconds(startDate: Date, endDate: Date, isCheckTimeZone: boolean): number {
|
|
678
|
+
const sDate: Date = new Date(startDate.getTime()); const eDate: Date = new Date(endDate.getTime());
|
|
679
|
+
let timeDiff: number = 0;
|
|
680
|
+
sDate.setDate(sDate.getDate() + 1);
|
|
681
|
+
sDate.setHours(0, 0, 0, 0);
|
|
682
|
+
eDate.setHours(0, 0, 0, 0);
|
|
683
|
+
if (sDate.getTime() < eDate.getTime()) {
|
|
684
|
+
timeDiff = (this.getTimeDifference(sDate, eDate, isCheckTimeZone)) / 1000;
|
|
685
|
+
}
|
|
686
|
+
if (timeDiff % 86400 !== 0) {
|
|
687
|
+
timeDiff = timeDiff - (timeDiff % 86400) + 86400;
|
|
688
|
+
}
|
|
689
|
+
return timeDiff;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
*
|
|
693
|
+
* @param {Date} startDate .
|
|
694
|
+
* @param {Date} endDate .
|
|
695
|
+
* @returns {number} .
|
|
696
|
+
*/
|
|
697
|
+
protected getHolidaysCount(startDate: Date, endDate: Date): number {
|
|
698
|
+
let holidaysCount: number = 0;
|
|
699
|
+
const holidays: number[] = this.parent.totalHolidayDates;
|
|
700
|
+
const sDate: Date = new Date(startDate.getTime());
|
|
701
|
+
const eDate: Date = new Date(endDate.getTime());
|
|
702
|
+
sDate.setDate(sDate.getDate() + 1);
|
|
703
|
+
sDate.setHours(0, 0, 0, 0);
|
|
704
|
+
eDate.setHours(0, 0, 0, 0);
|
|
705
|
+
if (sDate.getTime() < eDate.getTime()) {
|
|
706
|
+
for (let i: number = 0; i < holidays.length; i++) {
|
|
707
|
+
const currentHoliday: Date = this.getDateFromFormat(new Date(holidays[i]));
|
|
708
|
+
if (sDate.getTime() <= currentHoliday.getTime() && eDate.getTime() > currentHoliday.getTime()) {
|
|
709
|
+
if ((!this.parent.includeWeekend && this.parent.nonWorkingDayIndex.indexOf(currentHoliday.getDay()) === -1) ||
|
|
710
|
+
this.parent.includeWeekend) {
|
|
711
|
+
holidaysCount += 1;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return holidaysCount;
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* @returns {number[]} .
|
|
720
|
+
* @private
|
|
721
|
+
*/
|
|
722
|
+
public getHolidayDates(): number[] {
|
|
723
|
+
const holidays: HolidayModel[] = this.parent.holidays;
|
|
724
|
+
const holidayDates: number[] = [];
|
|
725
|
+
for (let i: number = 0; i < holidays.length; i++) {
|
|
726
|
+
const from: Date = this.getDateFromFormat(holidays[i].from);
|
|
727
|
+
const to: Date = this.getDateFromFormat(holidays[i].to);
|
|
728
|
+
if (isNullOrUndefined(from) && isNullOrUndefined(to)) {
|
|
729
|
+
continue;
|
|
730
|
+
} else if (isNullOrUndefined(from) || isNullOrUndefined(to)) {
|
|
731
|
+
const tempDate: Date = from ? from : to;
|
|
732
|
+
tempDate.setHours(0, 0, 0, 0);
|
|
733
|
+
if (holidayDates.indexOf(tempDate.getTime()) === -1) {
|
|
734
|
+
holidayDates.push(tempDate.getTime());
|
|
735
|
+
}
|
|
736
|
+
} else {
|
|
737
|
+
while (from <= to) {
|
|
738
|
+
from.setHours(0, 0, 0, 0);
|
|
739
|
+
if (holidayDates.indexOf(from.getTime()) === -1) {
|
|
740
|
+
holidayDates.push(from.getTime());
|
|
741
|
+
}
|
|
742
|
+
from.setDate(from.getDate() + 1);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return holidayDates;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* @param {Date} date .
|
|
750
|
+
* @param {boolean} checkWeekEnd .
|
|
751
|
+
* @returns {boolean} .
|
|
752
|
+
* @private
|
|
753
|
+
*/
|
|
754
|
+
/*Check given date is on holidays*/
|
|
755
|
+
public isOnHolidayOrWeekEnd(date: Date, checkWeekEnd: boolean): boolean {
|
|
756
|
+
checkWeekEnd = !isNullOrUndefined(checkWeekEnd) ? checkWeekEnd : this.parent.includeWeekend;
|
|
757
|
+
if (!checkWeekEnd && this.parent.nonWorkingDayIndex.indexOf(date.getDay()) !== -1) {
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
const holidays: number[] = this.parent.totalHolidayDates;
|
|
761
|
+
for (let count: number = 0; count < holidays.length; count++) {
|
|
762
|
+
const holidayFrom: Date = this.getDateFromFormat(new Date(holidays[count]));
|
|
763
|
+
const holidayTo: Date = new Date(holidayFrom.getTime());
|
|
764
|
+
holidayFrom.setHours(0, 0, 0, 0);
|
|
765
|
+
holidayTo.setHours(23, 59, 59, 59);
|
|
766
|
+
if (date.getTime() >= holidayFrom.getTime() && date.getTime() < holidayTo.getTime()) {
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* To calculate non working times in given date
|
|
774
|
+
*
|
|
775
|
+
* @param {Date} startDate .
|
|
776
|
+
* @param {Date} endDate .
|
|
777
|
+
* @param {boolean} isAutoSchedule .
|
|
778
|
+
* @returns {number} .
|
|
779
|
+
*/
|
|
780
|
+
protected getNonWorkingSecondsOnDate(startDate: Date, endDate: Date, isAutoSchedule: boolean): number {
|
|
781
|
+
const sHour: number = this.getSecondsInDecimal(startDate);
|
|
782
|
+
const eHour: number = this.getSecondsInDecimal(endDate);
|
|
783
|
+
let startRangeIndex: number = -1;
|
|
784
|
+
let endRangeIndex: number = -1;
|
|
785
|
+
let totNonWrkSecs: number = 0;
|
|
786
|
+
const startOnHoliday: boolean = isAutoSchedule ? this.isOnHolidayOrWeekEnd(startDate, null) : false;
|
|
787
|
+
const endOnHoliday: boolean = isAutoSchedule ? this.isOnHolidayOrWeekEnd(endDate, null) : false;
|
|
788
|
+
|
|
789
|
+
for (let i: number = 0; i < this.parent.nonWorkingTimeRanges.length; i++) {
|
|
790
|
+
const val: IWorkingTimeRange = this.parent.nonWorkingTimeRanges[i];
|
|
791
|
+
if (sHour >= val.from && sHour <= val.to) {
|
|
792
|
+
startRangeIndex = i;
|
|
793
|
+
}
|
|
794
|
+
if (eHour >= val.from && eHour <= val.to) {
|
|
795
|
+
endRangeIndex = i;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (startDate.getDate() !== endDate.getDate() || startDate.getMonth() !== endDate.getMonth() ||
|
|
799
|
+
startDate.getFullYear() !== endDate.getFullYear()) {
|
|
800
|
+
if (!startOnHoliday) {
|
|
801
|
+
for (let i: number = startRangeIndex; i < this.parent.nonWorkingTimeRanges.length; i++) {
|
|
802
|
+
if (!this.parent.nonWorkingTimeRanges[i].isWorking) {
|
|
803
|
+
if (i === startRangeIndex) {
|
|
804
|
+
totNonWrkSecs += (this.parent.nonWorkingTimeRanges[i].to - sHour);
|
|
805
|
+
} else {
|
|
806
|
+
totNonWrkSecs += (this.parent.nonWorkingTimeRanges[i].interval);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
totNonWrkSecs += (86400 - sHour);
|
|
812
|
+
}
|
|
813
|
+
if (!endOnHoliday) {
|
|
814
|
+
for (let i: number = 0; i <= endRangeIndex; i++) {
|
|
815
|
+
if (!this.parent.nonWorkingTimeRanges[i].isWorking) {
|
|
816
|
+
if (i === endRangeIndex) {
|
|
817
|
+
totNonWrkSecs += (eHour - this.parent.nonWorkingTimeRanges[i].from);
|
|
818
|
+
} else {
|
|
819
|
+
totNonWrkSecs += this.parent.nonWorkingTimeRanges[i].interval;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
} else {
|
|
824
|
+
totNonWrkSecs += eHour;
|
|
825
|
+
}
|
|
826
|
+
} else {
|
|
827
|
+
if (startRangeIndex !== endRangeIndex) {
|
|
828
|
+
if (!endOnHoliday) {
|
|
829
|
+
for (let i: number = startRangeIndex; i <= endRangeIndex; i++) {
|
|
830
|
+
if (!this.parent.nonWorkingTimeRanges[i].isWorking) {
|
|
831
|
+
if (i === startRangeIndex) {
|
|
832
|
+
totNonWrkSecs += (this.parent.nonWorkingTimeRanges[i].to - sHour);
|
|
833
|
+
} else if (i === endRangeIndex) {
|
|
834
|
+
totNonWrkSecs += (eHour - this.parent.nonWorkingTimeRanges[i].from);
|
|
835
|
+
} else {
|
|
836
|
+
totNonWrkSecs += this.parent.nonWorkingTimeRanges[i].interval;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
} else {
|
|
841
|
+
totNonWrkSecs += (eHour - sHour);
|
|
842
|
+
}
|
|
843
|
+
} else {
|
|
844
|
+
if (!endOnHoliday) {
|
|
845
|
+
const range: IWorkingTimeRange = this.parent.nonWorkingTimeRanges[startRangeIndex];
|
|
846
|
+
if (!range.isWorking) {
|
|
847
|
+
totNonWrkSecs = eHour - sHour;
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
totNonWrkSecs += (eHour - sHour);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return totNonWrkSecs;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
*
|
|
858
|
+
* @param {Date} date .
|
|
859
|
+
* @returns {Date} .
|
|
860
|
+
*/
|
|
861
|
+
protected getPreviousWorkingDay(date: Date): Date {
|
|
862
|
+
const dayIndex: number = date.getDay();
|
|
863
|
+
const previousIndex: number = (dayIndex === 0) ? 6 : dayIndex - 1;
|
|
864
|
+
if (this.parent.nonWorkingDayIndex.indexOf(dayIndex) !== -1 || (this.parent.nonWorkingDayIndex.indexOf(previousIndex) !== -1
|
|
865
|
+
&& this.parent.defaultEndTime === 86400 && this.getSecondsInDecimal(date) === 0)) {
|
|
866
|
+
date.setDate(date.getDate() - 1);
|
|
867
|
+
if (this.parent.nonWorkingDayIndex.indexOf(date.getDay()) !== -1) {
|
|
868
|
+
date = this.getPreviousWorkingDay(date);
|
|
869
|
+
}
|
|
870
|
+
return date;
|
|
871
|
+
} else {
|
|
872
|
+
return date;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* To get non-working day indexes.
|
|
877
|
+
*
|
|
878
|
+
* @returns {void} .
|
|
879
|
+
* @private
|
|
880
|
+
*/
|
|
881
|
+
public getNonWorkingDayIndex(): void {
|
|
882
|
+
const weekDay: string[] = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
|
883
|
+
const weekDayLength: number = weekDay.length;
|
|
884
|
+
if (this.parent.workWeek.length === 0) {
|
|
885
|
+
this.parent.workWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
|
886
|
+
}
|
|
887
|
+
const workWeek: string[] = this.parent.workWeek.slice();
|
|
888
|
+
const length: number = workWeek.length;
|
|
889
|
+
for (let i: number = 0; i < length; i++) {
|
|
890
|
+
workWeek[i] = workWeek[i].toLowerCase();
|
|
891
|
+
}
|
|
892
|
+
this.parent.nonWorkingDayIndex = [];
|
|
893
|
+
for (let i: number = 0; i < weekDayLength; i++) {
|
|
894
|
+
if (workWeek.indexOf(weekDay[i]) === -1) {
|
|
895
|
+
this.parent.nonWorkingDayIndex.push(i);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
*
|
|
901
|
+
* @param {number} seconds .
|
|
902
|
+
* @param {Date} date .
|
|
903
|
+
* @returns {void} .
|
|
904
|
+
* @private
|
|
905
|
+
*/
|
|
906
|
+
public setTime(seconds: number, date: Date): void {
|
|
907
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
908
|
+
let hour: any = seconds / 3600;
|
|
909
|
+
hour = parseInt(hour, 10);
|
|
910
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
911
|
+
let min: any = (seconds - (hour * 3600)) / 60;
|
|
912
|
+
min = parseInt(min, 10);
|
|
913
|
+
const sec: number = seconds - (hour * 3600) - (min * 60);
|
|
914
|
+
date.setHours(hour, min, sec);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* @param {Date} startDate .
|
|
918
|
+
* @param {Date} endDate .
|
|
919
|
+
* @param {boolean} isCheckTimeZone .
|
|
920
|
+
* @returns {number} .
|
|
921
|
+
*/
|
|
922
|
+
protected getTimeDifference(startDate: Date, endDate: Date, isCheckTimeZone?: boolean): number {
|
|
923
|
+
const sDate: Date = new Date(startDate.getTime()); const eDate: Date = new Date(endDate.getTime());
|
|
924
|
+
if (isCheckTimeZone) {
|
|
925
|
+
this.updateDateWithTimeZone(sDate, eDate);
|
|
926
|
+
}
|
|
927
|
+
return eDate.getTime() - sDate.getTime();
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* @param {Date} sDate .
|
|
931
|
+
* @param {Date} eDate .
|
|
932
|
+
* @returns {void} .
|
|
933
|
+
*/
|
|
934
|
+
protected updateDateWithTimeZone(sDate: Date, eDate: Date): void {
|
|
935
|
+
const sTZ: number = sDate.getTimezoneOffset();
|
|
936
|
+
const eTZ: number = eDate.getTimezoneOffset();
|
|
937
|
+
let uTZ: number; let uDate: Date;
|
|
938
|
+
if (sTZ !== eTZ) {
|
|
939
|
+
const standardTZ: number = new Date(new Date().getFullYear(), 0, 1).getTimezoneOffset();
|
|
940
|
+
if (standardTZ !== sTZ) {
|
|
941
|
+
uDate = sDate;
|
|
942
|
+
uTZ = sTZ;
|
|
943
|
+
} else if (standardTZ !== eTZ) {
|
|
944
|
+
uDate = eDate;
|
|
945
|
+
uTZ = eTZ;
|
|
946
|
+
}
|
|
947
|
+
if (standardTZ < 0) {
|
|
948
|
+
const tzDiff: number = standardTZ - uTZ;
|
|
949
|
+
uDate.setTime(uDate.getTime() + (tzDiff * 60 * 1000));
|
|
950
|
+
} else if (standardTZ >= 0) {
|
|
951
|
+
const tzDiff: number = uTZ - standardTZ;
|
|
952
|
+
uDate.setTime(uDate.getTime() - (tzDiff * 60 * 1000));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
*
|
|
958
|
+
* @param {Date} date .
|
|
959
|
+
* @returns {number} .
|
|
960
|
+
*/
|
|
961
|
+
protected getSecondsInDecimal(date: Date): number {
|
|
962
|
+
return (date.getHours() * 60 * 60) + (date.getMinutes() * 60) + date.getSeconds() + (date.getMilliseconds() / 1000);
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* @param {Date} date .
|
|
966
|
+
* @param {number} localOffset .
|
|
967
|
+
* @param {string} timezone .
|
|
968
|
+
* @returns {number} .
|
|
969
|
+
* @private
|
|
970
|
+
*/
|
|
971
|
+
|
|
972
|
+
public offset(date: Date, timezone: string): number {
|
|
973
|
+
const localOffset: number = date.getTimezoneOffset();
|
|
974
|
+
try {
|
|
975
|
+
const convertedDate: Date = new Date(date.toLocaleString('en-US', { timeZone: timezone }));
|
|
976
|
+
if (!isNaN(convertedDate.getTime())) {
|
|
977
|
+
return ((date.getTime() - convertedDate.getTime()) / 60000) + localOffset;
|
|
978
|
+
}
|
|
979
|
+
return 0;
|
|
980
|
+
} catch (error) {
|
|
981
|
+
return 0;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
public remove(date: Date, timezone: string): Date {
|
|
986
|
+
if (!isNullOrUndefined(date)) {
|
|
987
|
+
date = this.reverse(date, timezone, date.getTimezoneOffset());
|
|
988
|
+
}
|
|
989
|
+
return date;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
public reverse(date: Date, fromOffset: number | string, toOffset: number | string): Date {
|
|
993
|
+
if (typeof fromOffset === 'string') {
|
|
994
|
+
fromOffset = this.offset(date, fromOffset);
|
|
995
|
+
}
|
|
996
|
+
if (typeof toOffset === 'string') {
|
|
997
|
+
toOffset = this.offset(date, toOffset);
|
|
998
|
+
}
|
|
999
|
+
const fromLocalOffset: number = date.getTimezoneOffset();
|
|
1000
|
+
date = new Date(date.getTime() + (fromOffset - toOffset) * 60000);
|
|
1001
|
+
const toLocalOffset: number = date.getTimezoneOffset();
|
|
1002
|
+
return new Date(date.getTime() + (toLocalOffset - fromLocalOffset) * 60000);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* @param {Date} date .
|
|
1007
|
+
* @param {string} timezone .
|
|
1008
|
+
* @returns {Date} .
|
|
1009
|
+
* @private
|
|
1010
|
+
*/
|
|
1011
|
+
public convert(date: Date, timezone: string): Date {
|
|
1012
|
+
const fromOffset: number = date.getTimezoneOffset();
|
|
1013
|
+
const toOffset : number = this.offset(date, timezone);
|
|
1014
|
+
date = new Date(date.getTime() + (fromOffset - toOffset) * 60000);
|
|
1015
|
+
const toLocalOffset: number = date.getTimezoneOffset();
|
|
1016
|
+
return new Date(date.getTime() + (toLocalOffset - fromOffset) * 60000);
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* @param {string | Date} date .
|
|
1020
|
+
* @param {boolean} toConvert .
|
|
1021
|
+
* @returns {Date} .
|
|
1022
|
+
* @private
|
|
1023
|
+
*/
|
|
1024
|
+
public getDateFromFormat(date: string | Date , toConvert?: boolean): Date {
|
|
1025
|
+
let updatedDate: Date;
|
|
1026
|
+
if (isNullOrUndefined(date)) {
|
|
1027
|
+
return null;
|
|
1028
|
+
} else if (date instanceof Date) {
|
|
1029
|
+
updatedDate = new Date(date.getTime());
|
|
1030
|
+
} else {
|
|
1031
|
+
const dateObject: Date = this.parent.globalize.parseDate(date, { format: this.parent.getDateFormat(), type: 'dateTime' });
|
|
1032
|
+
updatedDate = isNullOrUndefined(dateObject) && !isNaN(new Date(date).getTime()) ? new Date(date) : dateObject;
|
|
1033
|
+
}
|
|
1034
|
+
if (!isNullOrUndefined(this.parent.timezone) && toConvert) {
|
|
1035
|
+
const convertedDate : Date = this.convert(updatedDate, this.parent.timezone);
|
|
1036
|
+
return convertedDate;
|
|
1037
|
+
}else {
|
|
1038
|
+
return updatedDate;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* @param {Date} date1 .
|
|
1043
|
+
* @param {Date} date2 .
|
|
1044
|
+
* @returns {number} .
|
|
1045
|
+
* @private
|
|
1046
|
+
*/
|
|
1047
|
+
public compareDates(date1: Date, date2: Date): number {
|
|
1048
|
+
if (!isNullOrUndefined(date1) && !isNullOrUndefined(date2)) {
|
|
1049
|
+
return (date1.getTime() > date2.getTime()) ? 1 : (date1.getTime() < date2.getTime()) ? -1 : 0;
|
|
1050
|
+
} else if (!isNullOrUndefined(date1) && isNullOrUndefined(date2)) {
|
|
1051
|
+
return 1;
|
|
1052
|
+
} else if (isNullOrUndefined(date1) && !isNullOrUndefined(date2)) {
|
|
1053
|
+
return -1;
|
|
1054
|
+
} else {
|
|
1055
|
+
return null;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
*
|
|
1060
|
+
* @param {number} duration .
|
|
1061
|
+
* @param {string} durationUnit .
|
|
1062
|
+
* @returns {string} .
|
|
1063
|
+
* @private
|
|
1064
|
+
*/
|
|
1065
|
+
public getDurationString(duration: number, durationUnit: string): string {
|
|
1066
|
+
let value: string = '';
|
|
1067
|
+
if (!isNullOrUndefined(duration)) {
|
|
1068
|
+
value += parseFloat(duration.toFixed(2)) + ' ';
|
|
1069
|
+
if (!isNullOrUndefined(durationUnit)) {
|
|
1070
|
+
const plural: boolean = duration !== 1;
|
|
1071
|
+
if (durationUnit === 'day') {
|
|
1072
|
+
value += plural ? this.parent.localeObj.getConstant('days') : this.parent.localeObj.getConstant('day');
|
|
1073
|
+
} else if (durationUnit === 'hour') {
|
|
1074
|
+
value += plural ? this.parent.localeObj.getConstant('hours') : this.parent.localeObj.getConstant('hour');
|
|
1075
|
+
} else if (durationUnit === 'minute') {
|
|
1076
|
+
value += plural ? this.parent.localeObj.getConstant('minutes') :
|
|
1077
|
+
this.parent.localeObj.getConstant('minute');
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return value;
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Method to get work with value and unit.
|
|
1085
|
+
*
|
|
1086
|
+
* @param {number} work .
|
|
1087
|
+
* @param {string} workUnit .
|
|
1088
|
+
* @returns {string} .
|
|
1089
|
+
* @private
|
|
1090
|
+
*/
|
|
1091
|
+
public getWorkString(work: number | string, workUnit: string): string {
|
|
1092
|
+
let value: string = '';
|
|
1093
|
+
if (!isNullOrUndefined(work)) {
|
|
1094
|
+
value += parseFloat(work as string).toFixed(2) + ' ';
|
|
1095
|
+
if (!isNullOrUndefined(workUnit)) {
|
|
1096
|
+
const plural: boolean = work !== 1;
|
|
1097
|
+
if (workUnit === 'day') {
|
|
1098
|
+
value += plural ? this.parent.localeObj.getConstant('days') : this.parent.localeObj.getConstant('day');
|
|
1099
|
+
} else if (workUnit === 'hour') {
|
|
1100
|
+
value += plural ? this.parent.localeObj.getConstant('hours') : this.parent.localeObj.getConstant('hour');
|
|
1101
|
+
} else if (workUnit === 'minute') {
|
|
1102
|
+
value += plural ? this.parent.localeObj.getConstant('minutes') :
|
|
1103
|
+
this.parent.localeObj.getConstant('minute');
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return value;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
*
|
|
1111
|
+
* @param {object} editArgs .
|
|
1112
|
+
* @returns {void} .
|
|
1113
|
+
* @private
|
|
1114
|
+
*/
|
|
1115
|
+
// eslint-disable-next-line
|
|
1116
|
+
public calculateProjectDatesForValidatedTasks(editArgs?: Object): void {
|
|
1117
|
+
const projectStartDate: Date = typeof this.parent.projectStartDate === 'string' ?
|
|
1118
|
+
new Date(this.parent.projectStartDate) : this.parent.projectStartDate;
|
|
1119
|
+
const projectEndDate: Date = typeof this.parent.projectEndDate === 'string' ?
|
|
1120
|
+
new Date(this.parent.projectEndDate) : this.parent.projectEndDate;
|
|
1121
|
+
let minStartDate: Date | string = null; let maxEndDate: Date| string = null;
|
|
1122
|
+
const flatData: object[] = (getValue('dataOperation.dataArray', this.parent));
|
|
1123
|
+
if ((!projectStartDate || !projectEndDate) && (flatData && flatData.length === 0)) {
|
|
1124
|
+
minStartDate = this.getDateFromFormat(new Date());
|
|
1125
|
+
maxEndDate = this.getDateFromFormat(new Date(minStartDate.getTime()));
|
|
1126
|
+
} else if (flatData.length > 0) {
|
|
1127
|
+
const sortedStartDate: object[] = flatData.slice().sort((a: ITaskData, b: ITaskData) =>
|
|
1128
|
+
((new Date(a[this.parent.taskFields.startDate])).getTime() -
|
|
1129
|
+
(new Date(b[this.parent.taskFields.startDate])).getTime()));
|
|
1130
|
+
const sortedEndDate: object[] = flatData.slice().sort((a: ITaskData, b: ITaskData) =>
|
|
1131
|
+
((new Date(b[this.parent.taskFields.endDate])).getTime() - (new Date(a[this.parent.taskFields.endDate])).getTime()));
|
|
1132
|
+
minStartDate = sortedStartDate[0][this.parent.taskFields.startDate];
|
|
1133
|
+
maxEndDate = sortedEndDate[sortedEndDate.length - 1][this.parent.taskFields.endDate];
|
|
1134
|
+
}
|
|
1135
|
+
this.parent.cloneProjectStartDate = projectStartDate ? new Date(projectStartDate.getTime()) :
|
|
1136
|
+
typeof minStartDate === 'string' ? new Date(minStartDate) : minStartDate;
|
|
1137
|
+
this.parent.cloneProjectEndDate = projectEndDate ? new Date(projectEndDate.getTime()) :
|
|
1138
|
+
typeof maxEndDate === 'string' ? new Date(maxEndDate) : maxEndDate;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
*
|
|
1142
|
+
* @param {object} editArgs .
|
|
1143
|
+
* @returns {void} .
|
|
1144
|
+
* @private
|
|
1145
|
+
*/
|
|
1146
|
+
public calculateProjectDates(editArgs?: Object): void {
|
|
1147
|
+
const sDate: Date = typeof this.parent.projectStartDate === 'string' ?
|
|
1148
|
+
new Date(this.parent.projectStartDate) : this.parent.projectStartDate;
|
|
1149
|
+
const eDate: Date = typeof this.parent.projectEndDate === 'string' ?
|
|
1150
|
+
new Date(this.parent.projectEndDate) : this.parent.projectEndDate;
|
|
1151
|
+
const projectStartDate: Date = this.parent.timelineModule.isZooming && this.parent.cloneProjectStartDate
|
|
1152
|
+
? this.getDateFromFormat(this.parent.cloneProjectStartDate) : this.getDateFromFormat(sDate);
|
|
1153
|
+
const projectEndDate: Date = this.parent.timelineModule.isZooming && this.parent.cloneProjectEndDate
|
|
1154
|
+
? this.getDateFromFormat(this.parent.cloneProjectEndDate) : this.getDateFromFormat(eDate);
|
|
1155
|
+
let minStartDate: Date = null; let maxEndDate: Date = null;
|
|
1156
|
+
const flatData: IGanttData[] = this.parent.flatData;
|
|
1157
|
+
const currentViewData: IGanttData[] = this.parent.currentViewData;
|
|
1158
|
+
let taskRange: Date[] = [];
|
|
1159
|
+
const addDateToList: Function = (date: Date): void => {
|
|
1160
|
+
if (!isNullOrUndefined(date)) {
|
|
1161
|
+
taskRange.push(date);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
const sortDates: Function = (dates: Date[]): void => {
|
|
1165
|
+
if (dates.length > 0) {
|
|
1166
|
+
dates.sort((a: Date, b: Date) => {
|
|
1167
|
+
return a.getTime() - b.getTime();
|
|
1168
|
+
});
|
|
1169
|
+
minStartDate = new Date(dates[0].getTime());
|
|
1170
|
+
maxEndDate = dates.length > 1 ? new Date(dates[dates.length - 1].getTime()) : null;
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
if (((!projectStartDate || !projectEndDate) && flatData.length > 0) || editArgs || this.parent.timelineModule.isZoomToFit) {
|
|
1174
|
+
let viewData: IGanttData[];
|
|
1175
|
+
if (currentViewData.length > 0 && this.parent.timelineModule.isZoomToFit &&
|
|
1176
|
+
this.parent.treeGrid.filterModule &&
|
|
1177
|
+
this.parent.treeGrid.filterModule.filteredResult.length > 0) {
|
|
1178
|
+
viewData = currentViewData;
|
|
1179
|
+
} else {
|
|
1180
|
+
viewData = flatData;
|
|
1181
|
+
}
|
|
1182
|
+
viewData.forEach((data: IGanttData) => {
|
|
1183
|
+
taskRange = [];
|
|
1184
|
+
const task: ITaskData = data.ganttProperties;
|
|
1185
|
+
const tempStartDate: Date = this.getValidStartDate(task);
|
|
1186
|
+
const tempEndDate: Date = this.getValidEndDate(task);
|
|
1187
|
+
addDateToList(minStartDate);
|
|
1188
|
+
addDateToList(maxEndDate);
|
|
1189
|
+
addDateToList(tempStartDate);
|
|
1190
|
+
addDateToList(tempEndDate);
|
|
1191
|
+
if (this.parent.renderBaseline && !this.parent.timelineModule.isZoomToFit) {
|
|
1192
|
+
addDateToList(task.baselineStartDate);
|
|
1193
|
+
addDateToList(task.baselineEndDate);
|
|
1194
|
+
}
|
|
1195
|
+
if (task.indicators && task.indicators.length > 0 && !this.parent.timelineModule.isZoomToFit) {
|
|
1196
|
+
task.indicators.forEach((item: IIndicator) => {
|
|
1197
|
+
addDateToList(this.getDateFromFormat(item.date));
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
sortDates(taskRange);
|
|
1201
|
+
});
|
|
1202
|
+
taskRange = [];
|
|
1203
|
+
addDateToList(minStartDate);
|
|
1204
|
+
addDateToList(maxEndDate);
|
|
1205
|
+
//update schedule dates as per holiday and strip line collection
|
|
1206
|
+
if (this.parent.eventMarkers.length > 0 && !this.parent.timelineModule.isZoomToFit) {
|
|
1207
|
+
const eventMarkers: EventMarkerModel[] = this.parent.eventMarkers;
|
|
1208
|
+
// eslint-disable-next-line
|
|
1209
|
+
eventMarkers.forEach((marker: EventMarkerModel, index: number) => {
|
|
1210
|
+
addDateToList(this.getDateFromFormat(marker.day));
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
if (this.parent.totalHolidayDates.length > 0 && !this.parent.timelineModule.isZoomToFit) {
|
|
1214
|
+
const holidays: number[] = this.parent.totalHolidayDates;
|
|
1215
|
+
// eslint-disable-next-line
|
|
1216
|
+
holidays.forEach((holiday: number, index: number) => {
|
|
1217
|
+
addDateToList(new Date(holiday));
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
sortDates(taskRange);
|
|
1221
|
+
|
|
1222
|
+
if (!minStartDate || !maxEndDate) {
|
|
1223
|
+
minStartDate = isNullOrUndefined(minStartDate) ? this.getDateFromFormat(new Date()) : minStartDate;
|
|
1224
|
+
maxEndDate = this.getDateFromFormat(new Date(minStartDate.getTime()));
|
|
1225
|
+
maxEndDate.setDate(maxEndDate.getDate() + 20);
|
|
1226
|
+
}
|
|
1227
|
+
} else if ((!projectStartDate || !projectEndDate) && flatData.length === 0) {
|
|
1228
|
+
minStartDate = this.getDateFromFormat(new Date());
|
|
1229
|
+
maxEndDate = this.getDateFromFormat(new Date(minStartDate.getTime()));
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if (!editArgs) {
|
|
1233
|
+
this.prevProjectStartDate = this.parent.cloneProjectStartDate;
|
|
1234
|
+
this.parent.cloneProjectStartDate = minStartDate ? minStartDate : new Date(projectStartDate.getTime());
|
|
1235
|
+
this.parent.cloneProjectEndDate = maxEndDate ? maxEndDate : new Date(projectEndDate.getTime());
|
|
1236
|
+
} else {
|
|
1237
|
+
setValue('minStartDate', minStartDate, editArgs);
|
|
1238
|
+
setValue('maxEndDate', maxEndDate, editArgs);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
*
|
|
1243
|
+
* @param {ITaskSegment} segments .
|
|
1244
|
+
* @returns {number} .
|
|
1245
|
+
* @private
|
|
1246
|
+
*/
|
|
1247
|
+
public splitTasksDuration(segments: ITaskSegment[]): number {
|
|
1248
|
+
let duration: number = 0;
|
|
1249
|
+
for (let i: number = 0; i < segments.length; i++) {
|
|
1250
|
+
const segment: ITaskSegment = segments[i];
|
|
1251
|
+
const sDate: Date = segment.startDate;
|
|
1252
|
+
const eDate: Date = segment.endDate;
|
|
1253
|
+
duration += Math.ceil(this.getTimeDifference(sDate, eDate) / (1000 * 60 * 60 * 24));
|
|
1254
|
+
}
|
|
1255
|
+
return duration;
|
|
1256
|
+
}
|
|
1257
|
+
}
|