@osimatic/helpers-js 1.0.71 → 1.0.72
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/date_time.js +79 -8
- package/network.js +1 -4
- package/package.json +1 -1
package/date_time.js
CHANGED
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
|
|
2
|
-
class
|
|
2
|
+
class DateTimeFormatter {
|
|
3
|
+
static getDateDigitalFormatter(locale, timeZone) {
|
|
4
|
+
if (this.dateDigitalFormatter == null) {
|
|
5
|
+
this.dateDigitalFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
|
|
6
|
+
}
|
|
3
7
|
|
|
8
|
+
return this.dateDigitalFormatter;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static getDateTextFormatter(locale, timeZone) {
|
|
12
|
+
if (this.dateTextFormatter == null) {
|
|
13
|
+
this.dateTextFormatter = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this.dateTextFormatter;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static getDateTimeFormatter(locale, timeZone) {
|
|
20
|
+
if (this.dateTimeFormatter == null) {
|
|
21
|
+
this.dateTimeFormatter = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return this.dateTimeFormatter;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static getDateSqlFormatter(timeZone) {
|
|
28
|
+
if (this.dateSqlFormatter == null) {
|
|
29
|
+
this.dateSqlFormatter = new Intl.DateTimeFormat('fr-FR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.dateSqlFormatter;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static getTimeSqlFormatter(timeZone) {
|
|
36
|
+
if (this.timeSqlFormatter == null) {
|
|
37
|
+
this.timeSqlFormatter = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this.timeSqlFormatter;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static getTimeFormatter(locale, timeZone) {
|
|
44
|
+
if (this.timeFormatter == null) {
|
|
45
|
+
this.timeFormatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return this.timeFormatter;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static getTimeDigitalFormatter(locale, timeZone) {
|
|
52
|
+
if (this.timeDigitalFormatter == null) {
|
|
53
|
+
this.timeDigitalFormatter = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.timeDigitalFormatter;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class DateTime {
|
|
4
61
|
static getSqlDate(jsDate, timeZone="Europe/Paris") {
|
|
5
|
-
|
|
62
|
+
return DateTimeFormatter.getDateSqlFormatter(timeZone).format(jsDate).replace(/\//g,'-').replace(',','');
|
|
63
|
+
|
|
64
|
+
//24/08/22 bad perfs
|
|
65
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
6
66
|
// return jsDate.getUTCFullYear() + '-' + pad(jsDate.getUTCMonth() + 1) + '-' + pad(jsDate.getUTCDate());
|
|
7
67
|
//return jsDate.getFullYear() + '-' + pad(jsDate.getMonth() + 1) + '-' + pad(jsDate.getDate());
|
|
8
68
|
return jsDate.toLocaleDateString('fr-FR', {year: 'numeric', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {month: '2-digit', timeZone: timeZone})+'-'+jsDate.toLocaleDateString('fr-FR', {day: '2-digit', timeZone: timeZone});
|
|
69
|
+
*/
|
|
9
70
|
}
|
|
10
71
|
|
|
11
72
|
static getSqlTime(jsDate, timeZone="Europe/Paris") {
|
|
12
|
-
|
|
73
|
+
return DateTimeFormatter.getTimeSqlFormatter(timeZone).format(jsDate);
|
|
74
|
+
/*let pad = function(num) { return ('00'+num).slice(-2) };
|
|
13
75
|
// return pad(jsDate.getUTCHours()) + ':' + pad(jsDate.getUTCMinutes()) + ':' + pad(jsDate.getUTCSeconds());
|
|
14
76
|
//return pad(jsDate.getHours()) + ':' + pad(jsDate.getMinutes()) + ':' + pad(jsDate.getSeconds());
|
|
15
77
|
return pad(jsDate.toLocaleTimeString('en-GB', {hour: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {minute: 'numeric', timeZone: timeZone}))+':'+pad(jsDate.toLocaleTimeString('en-GB', {second: 'numeric', timeZone: timeZone}));
|
|
78
|
+
*/
|
|
16
79
|
}
|
|
17
80
|
|
|
18
81
|
static getSqlDateTime(jsDate) {
|
|
@@ -24,18 +87,25 @@ class DateTime {
|
|
|
24
87
|
}
|
|
25
88
|
|
|
26
89
|
static getDateDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
27
|
-
return
|
|
90
|
+
return DateTimeFormatter.getDateDigitalFormatter(locale, timeZone).format(jsDate);
|
|
91
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
28
92
|
}
|
|
93
|
+
|
|
29
94
|
static getDateTextDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
30
|
-
return
|
|
95
|
+
return DateTimeFormatter.getDateTextFormatter(locale, timeZone).format(jsDate);
|
|
96
|
+
//return jsDate.toLocaleDateString(locale, {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
31
97
|
}
|
|
32
98
|
|
|
33
99
|
static getTimeDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
34
|
-
return
|
|
100
|
+
return DateTimeFormatter.getTimeFormatter(locale, timeZone).format(jsDate);
|
|
101
|
+
//return jsDate.toLocaleTimeString(locale, {hour: 'numeric', minute: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
35
102
|
}
|
|
103
|
+
|
|
36
104
|
static getTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
37
|
-
return
|
|
105
|
+
return DateTimeFormatter.getTimeDigitalFormatter(locale, timeZone).format(jsDate);
|
|
106
|
+
//return jsDate.toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone}); //24/08/22 bad perfs
|
|
38
107
|
}
|
|
108
|
+
|
|
39
109
|
static getTimeDisplayWithNbDays(jsDate, jsPreviousDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
40
110
|
let str = this.getTimeDisplay(jsDate, locale, timeZone);
|
|
41
111
|
if (jsPreviousDate != 0 && jsPreviousDate != null) {
|
|
@@ -48,7 +118,8 @@ class DateTime {
|
|
|
48
118
|
}
|
|
49
119
|
|
|
50
120
|
static getDateTimeDigitalDisplay(jsDate, locale="fr-FR", timeZone="Europe/Paris") {
|
|
51
|
-
return
|
|
121
|
+
return DateTimeFormatter.getDateTimeFormatter(locale, timeZone).format(jsDate);
|
|
122
|
+
//return jsDate.toLocaleDateString(locale, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone}); //24/08/22 bad perfs
|
|
52
123
|
}
|
|
53
124
|
|
|
54
125
|
static getYear(jsDate) {
|
package/network.js
CHANGED
|
@@ -227,16 +227,13 @@ class HTTPRequest {
|
|
|
227
227
|
|
|
228
228
|
const response = await fetch(url, requestInit);
|
|
229
229
|
try {
|
|
230
|
-
const blobData = await response.blob();
|
|
231
|
-
/*console.log(url);
|
|
232
|
-
console.log(blobData);*/
|
|
233
|
-
|
|
234
230
|
if (response.status === 401 && response.statusText === 'Expired JWT Token') {
|
|
235
231
|
HTTPRequest.refreshToken(() => HTTPRequest.download(url, data, errorCallback, completeCallback, method), errorCallback);
|
|
236
232
|
return;
|
|
237
233
|
}
|
|
238
234
|
|
|
239
235
|
if (response.ok) {
|
|
236
|
+
const blobData = await response.blob();
|
|
240
237
|
File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
|
|
241
238
|
}
|
|
242
239
|
else {
|