|
@@ -9,10 +9,33 @@ export default class PlanningEventManager {
|
9
|
9
|
*
|
10
|
10
|
* @return {string} The string representation
|
11
|
11
|
*/
|
12
|
|
- static getCurrentDateString() {
|
|
12
|
+ static getCurrentDateString(): string {
|
13
|
13
|
return PlanningEventManager.dateToString(new Date());
|
14
|
14
|
}
|
15
|
15
|
|
|
16
|
+ /**
|
|
17
|
+ * Gets how many days the event lasts. If no end date is specified, defaults to 1.
|
|
18
|
+ *
|
|
19
|
+ *
|
|
20
|
+ * @param start The start date string in format YYYY-MM-DD HH:MM:SS
|
|
21
|
+ * @param end The end date string in format YYYY-MM-DD HH:MM:SS
|
|
22
|
+ * @return {number} The number of days, 0 on error
|
|
23
|
+ */
|
|
24
|
+ static getEventDaysNumber(start: string, end: string): number {
|
|
25
|
+ let startDate = PlanningEventManager.stringToDate(start);
|
|
26
|
+ let endDate = PlanningEventManager.stringToDate(end);
|
|
27
|
+ if (startDate !== undefined && endDate !== undefined) {
|
|
28
|
+ if (startDate.getTime() !== endDate.getTime()) {
|
|
29
|
+ const diffTime = endDate - startDate;
|
|
30
|
+ return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
31
|
+ } else
|
|
32
|
+ return 1;
|
|
33
|
+ } else if (startDate !== undefined)
|
|
34
|
+ return 1;
|
|
35
|
+ else
|
|
36
|
+ return 0;
|
|
37
|
+ }
|
|
38
|
+
|
16
|
39
|
|
17
|
40
|
/**
|
18
|
41
|
* Checks if the given date is before the other.
|
|
@@ -89,26 +112,19 @@ export default class PlanningEventManager {
|
89
|
112
|
|
90
|
113
|
/**
|
91
|
114
|
* Converts a date object to a string in the format
|
92
|
|
- * YYYY-MM-DD
|
|
115
|
+ * YYYY-MM-DD HH-MM-SS
|
93
|
116
|
*
|
94
|
117
|
* @param date The date object to convert
|
95
|
118
|
* @return {string} The converted string
|
96
|
119
|
*/
|
97
|
120
|
static dateToString(date: Date) {
|
98
|
|
- let dd = String(date.getDate()).padStart(2, '0');
|
99
|
|
- let mm = String(date.getMonth() + 1).padStart(2, '0'); //January is 0!
|
100
|
|
- let yyyy = date.getFullYear();
|
101
|
|
- return yyyy + '-' + mm + '-' + dd;
|
102
|
|
- }
|
103
|
|
-
|
104
|
|
- /**
|
105
|
|
- * Returns a padded string for the given number if it is lower than 10
|
106
|
|
- *
|
107
|
|
- * @param i The string to be converted
|
108
|
|
- * @return {string}
|
109
|
|
- */
|
110
|
|
- static toPaddedString(i: number): string {
|
111
|
|
- return (i < 10 && i >= 0) ? "0" + i.toString(10) : i.toString(10);
|
|
121
|
+ const day = String(date.getDate()).padStart(2, '0');
|
|
122
|
+ const month = String(date.getMonth() + 1).padStart(2, '0'); //January is 0!
|
|
123
|
+ const year = date.getFullYear();
|
|
124
|
+ const hours = String(date.getHours()).padStart(2, '0');
|
|
125
|
+ const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
126
|
+ const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
127
|
+ return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
|
112
|
128
|
}
|
113
|
129
|
|
114
|
130
|
/**
|
|
@@ -118,7 +134,7 @@ export default class PlanningEventManager {
|
118
|
134
|
*
|
119
|
135
|
* If the end date is not specified or is equal to start time, only start time will be shown.
|
120
|
136
|
*
|
121
|
|
- * If the end date is not on the same day, 00:00 will be shown as end time
|
|
137
|
+ * If the end date is not on the same day, 23:59 will be shown as end time
|
122
|
138
|
*
|
123
|
139
|
* @param start Start time in YYYY-MM-DD HH:MM:SS format
|
124
|
140
|
* @param end End time in YYYY-MM-DD HH:MM:SS format
|
|
@@ -130,19 +146,19 @@ export default class PlanningEventManager {
|
130
|
146
|
let endDate = PlanningEventManager.stringToDate(end);
|
131
|
147
|
|
132
|
148
|
if (startDate !== undefined && endDate !== undefined && startDate.getTime() !== endDate.getTime()) {
|
133
|
|
- formattedStr = PlanningEventManager.toPaddedString(startDate.getHours()) + ':'
|
134
|
|
- + PlanningEventManager.toPaddedString(startDate.getMinutes()) + ' - ';
|
|
149
|
+ formattedStr = String(startDate.getHours()).padStart(2, '0') + ':'
|
|
150
|
+ + String(startDate.getMinutes()).padStart(2, '0') + ' - ';
|
135
|
151
|
if (endDate.getFullYear() > startDate.getFullYear()
|
136
|
152
|
|| endDate.getMonth() > startDate.getMonth()
|
137
|
153
|
|| endDate.getDate() > startDate.getDate())
|
138
|
|
- formattedStr += '00:00';
|
|
154
|
+ formattedStr += '23:59';
|
139
|
155
|
else
|
140
|
|
- formattedStr += PlanningEventManager.toPaddedString(endDate.getHours()) + ':'
|
141
|
|
- + PlanningEventManager.toPaddedString(endDate.getMinutes());
|
|
156
|
+ formattedStr += String(endDate.getHours()).padStart(2, '0') + ':'
|
|
157
|
+ + String(endDate.getMinutes()).padStart(2, '0');
|
142
|
158
|
} else if (startDate !== undefined)
|
143
|
159
|
formattedStr =
|
144
|
|
- PlanningEventManager.toPaddedString(startDate.getHours()) + ':'
|
145
|
|
- + PlanningEventManager.toPaddedString(startDate.getMinutes());
|
|
160
|
+ String(startDate.getHours()).padStart(2, '0') + ':'
|
|
161
|
+ + String(startDate.getMinutes()).padStart(2, '0');
|
146
|
162
|
|
147
|
163
|
return formattedStr
|
148
|
164
|
}
|