inviton-powerduck 0.0.153 → 0.0.155
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/app/powerduck-initializer.ts +3 -3
- package/common/api-http.ts +20 -14
- package/common/css/ladda-themeless-zoomin.min.css +89 -89
- package/common/enum-translation/day-translator.ts +3 -2
- package/common/excel/excel-reader.ts +2 -9
- package/common/extensions/array-extensions.ts +116 -0
- package/common/extensions/string-extensions.ts +92 -0
- package/common/extensions/temporal-extensions.ts +115 -0
- package/common/scroll-utils.ts +2 -1
- package/common/temporal-helpers.ts +551 -0
- package/common/throttled-api-caller.ts +149 -0
- package/common/timezone-helper.ts +39 -29
- package/common/utils/cookie.ts +11 -8
- package/common/utils/date-localization-utils.ts +25 -19
- package/common/utils/date-utils.ts +37 -47
- package/common/utils/form-utils.ts +3 -1
- package/common/utils/language-utils.ts +21 -27
- package/common/utils/temporal-utils.ts +43 -0
- package/common/utils/upload-image-helper.ts +1 -1
- package/common/utils/utils.ts +14 -14
- package/common/validation.ts +17 -5
- package/components/chart-js/line-chart-flot.tsx +9 -9
- package/components/chart-js/thirdparty/flot/jquery.flot.categories.min.js +93 -93
- package/components/chart-js/thirdparty/flot/jquery.flot.crosshair.min.js +83 -83
- package/components/chart-js/thirdparty/flot/jquery.flot.navigate.min.js +270 -270
- package/components/chart-js/thirdparty/flot/jquery.flot.pie.min.js +507 -507
- package/components/chart-js/thirdparty/flot/jquery.flot.resize.js +7 -9
- package/components/chart-js/thirdparty/flot/jquery.flot.resize.min.js +9 -11
- package/components/chart-js/thirdparty/flot/jquery.flot.stack.min.js +104 -104
- package/components/chart-js/ts/line-chart-contracts.ts +2 -2
- package/components/container-with-breakpoints/ts/breakpoint-handler.ts +2 -2
- package/components/counter/testall.tsx +89 -75
- package/components/datatable/datatable.tsx +2379 -2375
- package/components/datatable/export-excel-modal.tsx +12 -14
- package/components/datatable/ts/reorder.ts +4 -2
- package/components/dropdown/index.tsx +48 -22
- package/components/dropdown/mobile/legacy_fdd.ts +10 -11
- package/components/dropzone/gallery-dropzone.tsx +394 -382
- package/components/fullcalendar/fullcalendar-draggable-event.tsx +8 -7
- package/components/fullcalendar/timegrid-calendar.tsx +60 -67
- package/components/image-crop/image-cropping-modal.tsx +9 -8
- package/components/image-crop/upload-and-crop.tsx +162 -162
- package/components/image-crop/vendor/jquery.Jcrop.min.css +344 -344
- package/components/import/import-mapper.tsx +2 -2
- package/components/input/daterange-picker.tsx +502 -521
- package/components/input/datetime-picker.tsx +45 -50
- package/components/input/plugins/daterangepicker/daterangepicker.min.css +400 -400
- package/components/input/plugins/daterangepicker/jquery.daterangepicker.min.js +346 -339
- package/components/input/plugins/daterangepicker/jquery.daterangepicker.ts +580 -402
- package/components/input/radio-button-group.tsx +2 -2
- package/components/input/ts/dateInputHelper.ts +1 -0
- package/components/input/wysiwig.tsx +12 -7
- package/components/svg/skilift-svg.tsx +6 -6
- package/package.json +2 -1
- package/common/date-wrapper.ts +0 -422
- package/common/utils/array-extend.ts +0 -215
- package/common/utils/array-remove.ts +0 -10
- package/common/utils/array-sort.ts +0 -56
- package/common/utils/capitalize-string.ts +0 -11
- package/common/utils/format-string.ts +0 -14
- package/common/utils/latinize-string.ts +0 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
|
|
3
3
|
interface IRowWithTimezone {
|
|
4
4
|
TimezoneGmtOffset?: number;
|
|
@@ -6,20 +6,20 @@ interface IRowWithTimezone {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export default class TimezoneHelper {
|
|
9
|
-
public static isDST(targetDate:
|
|
10
|
-
const currMonth = targetDate.
|
|
9
|
+
public static isDST(targetDate: Temporal.PlainDateTime): boolean {
|
|
10
|
+
const currMonth = targetDate.month;
|
|
11
11
|
if (currMonth < 3) {
|
|
12
12
|
return false;
|
|
13
13
|
} else if (currMonth > 3 && currMonth < 10) {
|
|
14
14
|
return true;
|
|
15
15
|
} else if (currMonth == 3) {
|
|
16
|
-
if (targetDate.
|
|
16
|
+
if (targetDate.day >= this.getLastSunday(targetDate.month, targetDate.year).day) {
|
|
17
17
|
return true;
|
|
18
18
|
} else {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
} else if (currMonth == 10) {
|
|
22
|
-
if (targetDate.
|
|
22
|
+
if (targetDate.day >= this.getLastSunday(targetDate.month, targetDate.year).day) {
|
|
23
23
|
return false;
|
|
24
24
|
} else {
|
|
25
25
|
return true;
|
|
@@ -29,30 +29,38 @@ export default class TimezoneHelper {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
public static getLocalDateFromUTC(dateUTC:
|
|
33
|
-
public static getLocalDateFromUTC(dateUTC:
|
|
32
|
+
public static getLocalDateFromUTC(dateUTC: Temporal.PlainDateTime, dataRow: IRowWithTimezone): Temporal.PlainDateTime;
|
|
33
|
+
public static getLocalDateFromUTC(dateUTC: Temporal.PlainDateTime, dstOffset: number, gmtOffset: number): Temporal.PlainDateTime;
|
|
34
34
|
public static getLocalDateFromUTC(
|
|
35
|
-
dateUTC:
|
|
35
|
+
dateUTC: Temporal.PlainDateTime,
|
|
36
36
|
dstOffsetOrRow: number | IRowWithTimezone,
|
|
37
37
|
gmtOffset?: number,
|
|
38
|
-
):
|
|
39
|
-
if (dateUTC == null) {
|
|
38
|
+
): Temporal.PlainDateTime {
|
|
39
|
+
if (dateUTC == null) {
|
|
40
|
+
return null as any;
|
|
41
|
+
}
|
|
40
42
|
|
|
41
43
|
const tzRow = this.getRowWithTimezone(dstOffsetOrRow, gmtOffset);
|
|
42
|
-
return
|
|
44
|
+
return dateUTC.add({
|
|
45
|
+
milliseconds: ((this.isDST(dateUTC) ? tzRow.TimezoneDstOffset : tzRow.TimezoneGmtOffset) as any) * -1 * 60 * 1000,
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
public static getUTCFromLocalDate(dateUTC:
|
|
46
|
-
public static getUTCFromLocalDate(dateUTC:
|
|
49
|
+
public static getUTCFromLocalDate(dateUTC: Temporal.PlainDateTime, dataRow: IRowWithTimezone): Temporal.PlainDateTime;
|
|
50
|
+
public static getUTCFromLocalDate(dateUTC: Temporal.PlainDateTime, dstOffset: number, gmtOffset: number): Temporal.PlainDateTime;
|
|
47
51
|
public static getUTCFromLocalDate(
|
|
48
|
-
dateUTC:
|
|
52
|
+
dateUTC: Temporal.PlainDateTime,
|
|
49
53
|
dstOffsetOrRow: number | IRowWithTimezone,
|
|
50
54
|
gmtOffset?: number,
|
|
51
|
-
):
|
|
52
|
-
if (dateUTC == null) {
|
|
55
|
+
): Temporal.PlainDateTime {
|
|
56
|
+
if (dateUTC == null) {
|
|
57
|
+
return null as any;
|
|
58
|
+
}
|
|
53
59
|
|
|
54
60
|
const tzRow = this.getRowWithTimezone(dstOffsetOrRow, gmtOffset);
|
|
55
|
-
return
|
|
61
|
+
return dateUTC.add({
|
|
62
|
+
milliseconds: ((this.isDST(dateUTC) ? tzRow.TimezoneDstOffset : tzRow.TimezoneGmtOffset) as any) * 60 * 1000,
|
|
63
|
+
});
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
private static getRowWithTimezone(dstOffsetOrRow: number | IRowWithTimezone, gmtOffset?: number): IRowWithTimezone {
|
|
@@ -67,18 +75,20 @@ export default class TimezoneHelper {
|
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
private static getLastSunday(month, year):
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
private static getLastSunday(month: number, year: number): Temporal.PlainDateTime {
|
|
79
|
+
// first day of next month
|
|
80
|
+
const firstOfNextMonth = Temporal.PlainYearMonth.from({ year, month })
|
|
81
|
+
.add({ months: 1 })
|
|
82
|
+
.toPlainDate({ day: 1 });
|
|
83
|
+
|
|
84
|
+
// last day of target month
|
|
85
|
+
const lastOfMonth = firstOfNextMonth.subtract({ days: 1 });
|
|
86
|
+
|
|
87
|
+
// Temporal dayOfWeek: 1=Mon ... 7=Sun
|
|
88
|
+
const daysToSubtract = lastOfMonth.dayOfWeek % 7; // 0 if already Sunday
|
|
89
|
+
const lastSunday = lastOfMonth.subtract({ days: daysToSubtract });
|
|
75
90
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
do {
|
|
79
|
-
// Roll the days backwards until Sunday.
|
|
80
|
-
d.setDate(d.getDate() - 1);
|
|
81
|
-
} while (d.getDay() !== 0);
|
|
82
|
-
return d;
|
|
91
|
+
// return as PlainDateTime at 00:00
|
|
92
|
+
return lastSunday.toPlainDateTime({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
83
93
|
}
|
|
84
94
|
}
|
package/common/utils/cookie.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
1
2
|
import { DomainHelper } from './domain-helper';
|
|
2
3
|
|
|
3
4
|
// Cookie manipulation abstraction
|
|
@@ -12,7 +13,7 @@ export class CookieProvider {
|
|
|
12
13
|
static set(
|
|
13
14
|
name: string,
|
|
14
15
|
value: string,
|
|
15
|
-
expiration?:
|
|
16
|
+
expiration?: Temporal.PlainDateTime,
|
|
16
17
|
) {
|
|
17
18
|
let domain = DomainHelper.getCookieDomain();
|
|
18
19
|
if (domain.length > 0) {
|
|
@@ -21,12 +22,12 @@ export class CookieProvider {
|
|
|
21
22
|
|
|
22
23
|
let realExpiration;
|
|
23
24
|
if (expiration != null) {
|
|
24
|
-
realExpiration = expiration.
|
|
25
|
+
realExpiration = expiration.toZonedDateTime('UTC').epochMilliseconds;
|
|
25
26
|
} else {
|
|
26
27
|
realExpiration = '';
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)};expires=${
|
|
30
|
+
document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)};expires=${realExpiration}${domain};path=/`;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -39,8 +40,12 @@ export class CookieProvider {
|
|
|
39
40
|
const ca = document.cookie.split(';');
|
|
40
41
|
for (let i = 0; i < ca.length; i++) {
|
|
41
42
|
let c = ca[i];
|
|
42
|
-
while (c.charAt(0) == ' ') {
|
|
43
|
-
|
|
43
|
+
while (c.charAt(0) == ' ') {
|
|
44
|
+
c = c.substring(1);
|
|
45
|
+
}
|
|
46
|
+
if (c.includes(name)) {
|
|
47
|
+
return c.substring(name.length, c.length);
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
50
|
return null;
|
|
46
51
|
}
|
|
@@ -51,12 +56,10 @@ export class CookieProvider {
|
|
|
51
56
|
* @param name Name of the cookie
|
|
52
57
|
*/
|
|
53
58
|
static remove(name: string) {
|
|
54
|
-
const someDate = new Date(); // add arguments as needed
|
|
55
|
-
someDate.setTime(someDate.getTime() - 3 * 28 * 24 * 60 * 60);
|
|
56
59
|
CookieProvider.set(
|
|
57
60
|
name,
|
|
58
61
|
'',
|
|
59
|
-
|
|
62
|
+
Temporal.PlainDateTime.from('1990-01-01'),
|
|
60
63
|
);
|
|
61
64
|
}
|
|
62
65
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { DateWrapper } from '../date-wrapper';
|
|
2
1
|
// Due to some limitations of Date Internationalization API, this hacks are applied
|
|
2
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
3
3
|
import PowerduckState from '../../app/powerduck-state';
|
|
4
|
-
import { capitalize } from '
|
|
4
|
+
import { capitalize } from '../extensions/string-extensions';
|
|
5
5
|
|
|
6
6
|
export default class DateLocalizationUtils {
|
|
7
7
|
private static readonly DATE_FORMAT_FOR_RANGE_PICKER = (function () {
|
|
8
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
8
9
|
const dummyDate = new Date(Date.UTC(
|
|
9
10
|
2022,
|
|
10
11
|
11,
|
|
@@ -21,6 +22,7 @@ export default class DateLocalizationUtils {
|
|
|
21
22
|
})();
|
|
22
23
|
|
|
23
24
|
private static readonly MONTH_IS_FIRST: boolean = (function () {
|
|
25
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
24
26
|
const dummyDate = new Date(Date.UTC(
|
|
25
27
|
2024,
|
|
26
28
|
9,
|
|
@@ -42,6 +44,7 @@ export default class DateLocalizationUtils {
|
|
|
42
44
|
})();
|
|
43
45
|
|
|
44
46
|
private static readonly PATTERN_WITHOUT_YEAR: string = (function () {
|
|
47
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
45
48
|
const dummyDate = new Date(Date.UTC(
|
|
46
49
|
2024,
|
|
47
50
|
9,
|
|
@@ -67,6 +70,7 @@ export default class DateLocalizationUtils {
|
|
|
67
70
|
})();
|
|
68
71
|
|
|
69
72
|
private static readonly PATTERN_WITH_YEAR: string = (function () {
|
|
73
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
70
74
|
const dummyDate = new Date(Date.UTC(
|
|
71
75
|
2024,
|
|
72
76
|
9,
|
|
@@ -93,6 +97,7 @@ export default class DateLocalizationUtils {
|
|
|
93
97
|
})();
|
|
94
98
|
|
|
95
99
|
private static readonly PATTERN_PLACEHOLDERED: string = (function () {
|
|
100
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
96
101
|
const dummyDate = new Date(Date.UTC(
|
|
97
102
|
2024,
|
|
98
103
|
9,
|
|
@@ -116,12 +121,13 @@ export default class DateLocalizationUtils {
|
|
|
116
121
|
}
|
|
117
122
|
})();
|
|
118
123
|
|
|
119
|
-
static formatRange = (from:
|
|
120
|
-
if (from.
|
|
124
|
+
static formatRange = (from: Temporal.PlainDateTime, to: Temporal.PlainDateTime): string => {
|
|
125
|
+
if (from.month == to.month) {
|
|
126
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
121
127
|
const convertDate = new Date(Date.UTC(
|
|
122
|
-
from.
|
|
123
|
-
from.
|
|
124
|
-
from.
|
|
128
|
+
from.year,
|
|
129
|
+
from.month - 1,
|
|
130
|
+
from.day,
|
|
125
131
|
));
|
|
126
132
|
convertDate.setDate(28);
|
|
127
133
|
|
|
@@ -132,10 +138,10 @@ export default class DateLocalizationUtils {
|
|
|
132
138
|
}).split('28').join('').split('.').join('').trim();
|
|
133
139
|
|
|
134
140
|
return this.PATTERN_WITH_YEAR
|
|
135
|
-
.replace('{{day}}', `${from.
|
|
141
|
+
.replace('{{day}}', `${from.day} - ${to.day}`)
|
|
136
142
|
.replace('{{month}}', monthName)
|
|
137
|
-
.replace('{{year}}', from.
|
|
138
|
-
} else if (from.
|
|
143
|
+
.replace('{{year}}', from.year.toString());
|
|
144
|
+
} else if (from.year == to.year) {
|
|
139
145
|
const fromDate = this.getFormatted(
|
|
140
146
|
from,
|
|
141
147
|
this.PATTERN_WITHOUT_YEAR,
|
|
@@ -149,7 +155,7 @@ export default class DateLocalizationUtils {
|
|
|
149
155
|
'short',
|
|
150
156
|
);
|
|
151
157
|
const rangeVal = `${fromDate} - ${toDate}`;
|
|
152
|
-
return this.PATTERN_PLACEHOLDERED.replace('{{date}}', rangeVal).replace('{{year}}', to.
|
|
158
|
+
return this.PATTERN_PLACEHOLDERED.replace('{{date}}', rangeVal).replace('{{year}}', to.year.toString());
|
|
153
159
|
} else {
|
|
154
160
|
const fromVal = this.getFormatted(
|
|
155
161
|
from,
|
|
@@ -170,7 +176,7 @@ export default class DateLocalizationUtils {
|
|
|
170
176
|
};
|
|
171
177
|
|
|
172
178
|
static getFormatedDateWithoutTime = (
|
|
173
|
-
dte:
|
|
179
|
+
dte: Temporal.PlainDateTime,
|
|
174
180
|
showYear: boolean,
|
|
175
181
|
day: 'numeric' | '2-digit' | undefined,
|
|
176
182
|
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' | undefined,
|
|
@@ -195,7 +201,7 @@ export default class DateLocalizationUtils {
|
|
|
195
201
|
};
|
|
196
202
|
|
|
197
203
|
private static getFormatted = (
|
|
198
|
-
dte:
|
|
204
|
+
dte: Temporal.PlainDateTime,
|
|
199
205
|
pattern: string,
|
|
200
206
|
day: 'numeric' | '2-digit' | undefined,
|
|
201
207
|
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' | undefined,
|
|
@@ -203,28 +209,28 @@ export default class DateLocalizationUtils {
|
|
|
203
209
|
): string => {
|
|
204
210
|
let monthVal: string;
|
|
205
211
|
try {
|
|
206
|
-
monthVal =
|
|
212
|
+
monthVal = dte.toLocaleString(PowerduckState.getCurrentLanguage(), {
|
|
207
213
|
month,
|
|
208
214
|
timeZone: 'UTC',
|
|
209
|
-
}));
|
|
215
|
+
})[capitalize]();
|
|
210
216
|
} catch (error) {
|
|
211
|
-
monthVal =
|
|
217
|
+
monthVal = dte.month.toString();
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
let dayVal: string;
|
|
215
221
|
if (day == '2-digit') {
|
|
216
|
-
dayVal = dte.
|
|
222
|
+
dayVal = dte.day.toString();
|
|
217
223
|
if (dayVal.length == 1) {
|
|
218
224
|
dayVal = `0${dayVal}`;
|
|
219
225
|
}
|
|
220
226
|
} else {
|
|
221
|
-
dayVal = dte.
|
|
227
|
+
dayVal = dte.day.toString();
|
|
222
228
|
}
|
|
223
229
|
|
|
224
230
|
if (year == null) {
|
|
225
231
|
return pattern.replace('{{day}}', dayVal).replace('{{month}}', monthVal);
|
|
226
232
|
} else {
|
|
227
|
-
return pattern.replace('{{day}}', dayVal).replace('{{month}}', monthVal).replace('{{year}}', dte.
|
|
233
|
+
return pattern.replace('{{day}}', dayVal).replace('{{month}}', monthVal).replace('{{year}}', dte.year.toString());
|
|
228
234
|
}
|
|
229
235
|
};
|
|
230
236
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
1
2
|
import PowerduckState from '../../app/powerduck-state';
|
|
2
|
-
import { DateWrapper } from '../date-wrapper';
|
|
3
3
|
|
|
4
4
|
const _isInteger = (val: any) => {
|
|
5
5
|
const digits = '1234567890';
|
|
@@ -31,29 +31,9 @@ const _getInt = (
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export default class DateUtils {
|
|
34
|
-
static
|
|
35
|
-
const target = new Date(date.getTime());
|
|
36
|
-
// Nastaviť na najbližší štvrtok (ISO týždne začínajú v pondelok)
|
|
37
|
-
target.setHours(
|
|
38
|
-
0,
|
|
39
|
-
0,
|
|
40
|
-
0,
|
|
41
|
-
0,
|
|
42
|
-
);
|
|
43
|
-
target.setDate(target.getDate() + 3 - ((target.getDay() + 6) % 7));
|
|
44
|
-
const firstThursday = new Date(
|
|
45
|
-
target.getFullYear(),
|
|
46
|
-
0,
|
|
47
|
-
4,
|
|
48
|
-
);
|
|
49
|
-
firstThursday.setDate(firstThursday.getDate() + 3 - ((firstThursday.getDay() + 6) % 7));
|
|
50
|
-
const weekNumber = 1 + Math.round(((target.getTime() - firstThursday.getTime()) / 86400000 - 3) / 7);
|
|
51
|
-
return weekNumber;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static formatDate (date: Date | DateWrapper | number, format: string): string {
|
|
34
|
+
static formatDate(date: Temporal.PlainDateTime | number, format: string): string {
|
|
55
35
|
if (typeof date === 'number') {
|
|
56
|
-
date =
|
|
36
|
+
date = Temporal.Instant.fromEpochMilliseconds(date as number).toZonedDateTimeISO('UTC').toPlainDateTime();
|
|
57
37
|
}
|
|
58
38
|
|
|
59
39
|
format = `${format}`;
|
|
@@ -61,13 +41,12 @@ export default class DateUtils {
|
|
|
61
41
|
let i_format = 0;
|
|
62
42
|
let c = '';
|
|
63
43
|
let token = '';
|
|
64
|
-
let y = `${date.
|
|
65
|
-
const M = date.
|
|
66
|
-
const d = date.
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const s = date.getSeconds();
|
|
44
|
+
let y = `${date.year}`;
|
|
45
|
+
const M = date.month;
|
|
46
|
+
const d = date.day;
|
|
47
|
+
const H = date.hour;
|
|
48
|
+
const m = date.minute;
|
|
49
|
+
const s = date.second;
|
|
71
50
|
const LZ = x => (x < 0 || x > 9 ? '' : '0') + x;
|
|
72
51
|
|
|
73
52
|
const locale = PowerduckState.getCurrentLanguage();
|
|
@@ -83,12 +62,12 @@ export default class DateUtils {
|
|
|
83
62
|
value.yy = y.substring(2, 4);
|
|
84
63
|
value.M = M;
|
|
85
64
|
value.MM = LZ(M);
|
|
86
|
-
value.MMM = date.
|
|
87
|
-
value.MMMM = date.
|
|
65
|
+
value.MMM = date.toLocaleString(locale, { month: 'short', timeZone: 'UTC' });
|
|
66
|
+
value.MMMM = date.toLocaleString(locale, { month: 'long', timeZone: 'UTC' });
|
|
88
67
|
value.d = d;
|
|
89
68
|
value.dd = LZ(d);
|
|
90
|
-
value.E = date.
|
|
91
|
-
value.EEEE = date.
|
|
69
|
+
value.E = date.toLocaleString(locale, { weekday: 'short', timeZone: 'UTC' });
|
|
70
|
+
value.EEEE = date.toLocaleString(locale, { weekday: 'long', timeZone: 'UTC' });
|
|
92
71
|
value.H = H;
|
|
93
72
|
value.HH = LZ(H);
|
|
94
73
|
if (H == 0) {
|
|
@@ -134,7 +113,7 @@ export default class DateUtils {
|
|
|
134
113
|
return result;
|
|
135
114
|
};
|
|
136
115
|
|
|
137
|
-
static
|
|
116
|
+
static getTemporalFromFormat(val: string, format: string): Temporal.PlainDateTime {
|
|
138
117
|
// In case somehow the date is already a datewrapper
|
|
139
118
|
if ((val as any)._dte != null) {
|
|
140
119
|
return (val as any);
|
|
@@ -147,6 +126,7 @@ export default class DateUtils {
|
|
|
147
126
|
let c = '';
|
|
148
127
|
let token = '';
|
|
149
128
|
let x, y;
|
|
129
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
150
130
|
const now = new Date();
|
|
151
131
|
let year: any = now.getFullYear();
|
|
152
132
|
let month: any = now.getMonth() + 1;
|
|
@@ -159,13 +139,18 @@ export default class DateUtils {
|
|
|
159
139
|
const _isValidChar = (char: string): boolean => /[a-záčďéíĺľńóôŕšťúýž]/i.test(char);
|
|
160
140
|
const locale = PowerduckState.getCurrentLanguage();
|
|
161
141
|
const getMonthFromName = (monthName: string, isShort: boolean = false): number => {
|
|
162
|
-
|
|
142
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
143
|
+
const date = new Date(
|
|
144
|
+
2022,
|
|
145
|
+
0,
|
|
146
|
+
1,
|
|
147
|
+
);
|
|
163
148
|
|
|
164
149
|
for (let monthIndex = 0; monthIndex < 12; monthIndex++) {
|
|
165
150
|
date.setMonth(monthIndex);
|
|
166
151
|
const name = date.toLocaleDateString(locale, {
|
|
167
152
|
month: isShort ? 'short' : 'long',
|
|
168
|
-
timeZone: 'UTC'
|
|
153
|
+
timeZone: 'UTC',
|
|
169
154
|
}).toLowerCase();
|
|
170
155
|
|
|
171
156
|
if (name == monthName.toLowerCase()) {
|
|
@@ -177,13 +162,18 @@ export default class DateUtils {
|
|
|
177
162
|
};
|
|
178
163
|
|
|
179
164
|
const getDayFromName = (dayName: string, isShort: boolean = false): number => {
|
|
180
|
-
|
|
165
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
166
|
+
const date = new Date(
|
|
167
|
+
2022,
|
|
168
|
+
0,
|
|
169
|
+
2,
|
|
170
|
+
);
|
|
181
171
|
|
|
182
172
|
for (let dayIndex = 0; dayIndex < 7; dayIndex++) {
|
|
183
173
|
date.setDate(2 + dayIndex);
|
|
184
174
|
const name = date.toLocaleDateString(locale, {
|
|
185
175
|
weekday: isShort ? 'short' : 'long',
|
|
186
|
-
timeZone: 'UTC'
|
|
176
|
+
timeZone: 'UTC',
|
|
187
177
|
}).toLowerCase();
|
|
188
178
|
|
|
189
179
|
if (name == dayName.toLowerCase()) {
|
|
@@ -463,13 +453,13 @@ export default class DateUtils {
|
|
|
463
453
|
hh -= 12;
|
|
464
454
|
}
|
|
465
455
|
|
|
466
|
-
return
|
|
467
|
-
Number(year),
|
|
468
|
-
Number(month)
|
|
469
|
-
Number(date),
|
|
470
|
-
Number(hh),
|
|
471
|
-
Number(mm),
|
|
472
|
-
Number(ss),
|
|
473
|
-
);
|
|
456
|
+
return Temporal.PlainDateTime.from({
|
|
457
|
+
year: Number(year),
|
|
458
|
+
month: Number(month),
|
|
459
|
+
day: Number(date),
|
|
460
|
+
hour: Number(hh),
|
|
461
|
+
minute: Number(mm),
|
|
462
|
+
second: Number(ss),
|
|
463
|
+
});
|
|
474
464
|
}
|
|
475
465
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import TemporalUtils from './temporal-utils';
|
|
2
|
+
|
|
1
3
|
export interface FormUtilsField {
|
|
2
4
|
name: string;
|
|
3
5
|
value: string;
|
|
@@ -27,7 +29,7 @@ export default class FormUtils {
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
const formMethod = 'POST';
|
|
30
|
-
const formName = `frm${
|
|
32
|
+
const formName = `frm${TemporalUtils.dateNowMs()}`;
|
|
31
33
|
let newForm = `<form id="${formName}" method="${formMethod}" action="${url}" ${newWindow == true ? 'target="_blank"' : ''}>`;
|
|
32
34
|
|
|
33
35
|
arr.forEach((field) => {
|
|
@@ -2,10 +2,12 @@ import type { Currency } from '../enums/currency';
|
|
|
2
2
|
import PowerduckState from '../../app/powerduck-state';
|
|
3
3
|
import LanguageTranslator from '../enum-translation/language-translator';
|
|
4
4
|
import { Language } from '../enums/language';
|
|
5
|
-
import {
|
|
5
|
+
import { sortBy } from '../extensions/array-extensions';
|
|
6
6
|
|
|
7
|
+
// eslint-disable-next-line ts/no-namespace
|
|
7
8
|
export namespace LanguageUtils {
|
|
8
|
-
|
|
9
|
+
// eslint-disable-next-line import/no-mutable-exports, prefer-const
|
|
10
|
+
export let supportedLanguages = [
|
|
9
11
|
Language.sk,
|
|
10
12
|
Language.en,
|
|
11
13
|
];
|
|
@@ -17,15 +19,15 @@ export namespace LanguageUtils {
|
|
|
17
19
|
id: Language;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const getAdjectiveName = (name: string): string => {
|
|
21
23
|
if (name.endsWith('ý')) {
|
|
22
24
|
name = `${name.substring(0, name.length - 1)}y`;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
return name;
|
|
26
|
-
}
|
|
28
|
+
};
|
|
27
29
|
|
|
28
|
-
export
|
|
30
|
+
export const getLanguageList = (sort?: boolean): Array<LanguageListItem> => {
|
|
29
31
|
const retVal = <Array<LanguageListItem>>[];
|
|
30
32
|
|
|
31
33
|
const getLanguage = (langCode: Language): LanguageListItem => {
|
|
@@ -81,43 +83,37 @@ export namespace LanguageUtils {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
if (sort === true) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
arraySort(retVal, 'text');
|
|
86
|
+
try {
|
|
87
|
+
retVal.sort((a, b) => a.text.localeCompare(b.text));
|
|
88
|
+
} catch (e) {
|
|
89
|
+
retVal[sortBy](p => p.text);
|
|
90
|
+
}
|
|
90
91
|
}
|
|
91
|
-
}
|
|
92
92
|
|
|
93
|
-
LanguageUtils.getLanguageList =
|
|
94
|
-
return retVal;
|
|
95
|
-
};
|
|
93
|
+
(LanguageUtils as any).getLanguageList = () => retVal;
|
|
96
94
|
return retVal;
|
|
97
|
-
}
|
|
95
|
+
};
|
|
98
96
|
|
|
99
97
|
/**
|
|
100
98
|
* Returns enum value from string language code
|
|
101
99
|
*
|
|
102
100
|
* @param langCode 2-letter language code [sk, en, cs...]
|
|
103
101
|
*/
|
|
104
|
-
export
|
|
105
|
-
return (langCode as any) ?? Language.en;
|
|
106
|
-
}
|
|
102
|
+
export const getLanguageEnum = (langCode: string): Language => (langCode as any) ?? Language.en;
|
|
107
103
|
|
|
108
|
-
export
|
|
104
|
+
export const getLanguageFlagUrl = (languageFlag: string, svg?: boolean): string => {
|
|
109
105
|
if (!svg) {
|
|
110
106
|
return `${PowerduckState.getAssetRootDirectory()}/img/flags/${languageFlag}.png`;
|
|
111
107
|
} else {
|
|
112
108
|
return `${PowerduckState.getAssetRootDirectory()}/img/flags/svg/${languageFlag}.svg`;
|
|
113
109
|
}
|
|
114
|
-
}
|
|
110
|
+
};
|
|
115
111
|
|
|
116
|
-
export
|
|
112
|
+
export const floatToCurrency = (
|
|
117
113
|
value: number,
|
|
118
114
|
currency: string | Currency | number | any,
|
|
119
115
|
killZeroCents?: boolean,
|
|
120
|
-
): string {
|
|
116
|
+
): string => {
|
|
121
117
|
let currencyISO: string;
|
|
122
118
|
if (currency == null || currency == '') {
|
|
123
119
|
currencyISO = '?';
|
|
@@ -144,9 +140,7 @@ export namespace LanguageUtils {
|
|
|
144
140
|
return `${(Math.round(value * 100) / 100).toString()} ${currencyISO}`;
|
|
145
141
|
}
|
|
146
142
|
}
|
|
147
|
-
}
|
|
143
|
+
};
|
|
148
144
|
|
|
149
|
-
export
|
|
150
|
-
return PowerduckState.getResourceValue('negationBase') + str.toLowerCase();
|
|
151
|
-
}
|
|
145
|
+
export const negateString = (str: string): string => PowerduckState.getResourceValue('negationBase') + str.toLowerCase();
|
|
152
146
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import { isNullOrEmpty } from './is-null-or-empty';
|
|
3
|
+
|
|
4
|
+
export default class TemporalUtils {
|
|
5
|
+
/*
|
|
6
|
+
* Returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.
|
|
7
|
+
*/
|
|
8
|
+
static dateNowMs(): number {
|
|
9
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
10
|
+
return new Date().getTime();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static isSerializedDate(str: string): boolean {
|
|
14
|
+
return str != null && str.length > 18 && str.length < 29 && str.indexOf('T') == 10;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static fromDate(d: Date): Temporal.PlainDateTime {
|
|
18
|
+
if (d == null) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Temporal.PlainDateTime.from({
|
|
23
|
+
year: d.getFullYear(),
|
|
24
|
+
month: d.getMonth() + 1, // JS Date months are 0-based
|
|
25
|
+
day: d.getDate(),
|
|
26
|
+
hour: d.getHours(),
|
|
27
|
+
minute: d.getMinutes(),
|
|
28
|
+
second: d.getSeconds(),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromString(val: string): Temporal.PlainDateTime {
|
|
33
|
+
if (isNullOrEmpty(val)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return Temporal.PlainDateTime.from(val.split('Z')[0]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static fromEpochMs(val: number): Temporal.PlainDateTime {
|
|
41
|
+
return Temporal.Instant.fromEpochMilliseconds(val).toZonedDateTimeISO('UTC').toPlainDateTime();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -27,7 +27,7 @@ compressionMaxMb: number = 0.5,
|
|
|
27
27
|
method: 'POST',
|
|
28
28
|
body: formData,
|
|
29
29
|
headers: {
|
|
30
|
-
|
|
30
|
+
[AppHttpProvider.authorizationHeaderName]: `Bearer ${AppHttpProvider.bearerToken}`,
|
|
31
31
|
'Accept-Language': PowerduckState.getCurrentLanguage(),
|
|
32
32
|
},
|
|
33
33
|
});
|