@osimatic/helpers-js 1.1.3 → 1.1.4
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 +29 -21
- package/http_client.js +10 -10
- package/package.json +1 -1
package/date_time.js
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
1
|
|
|
2
2
|
class DateTimeFormatter {
|
|
3
3
|
static getDateDigitalFormatter(locale, timeZone) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
this.dateDigitalFormatter = this.dateDigitalFormatter || {};
|
|
5
|
+
if (typeof this.dateDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
6
|
+
this.dateDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', timeZone: timeZone });
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
return this.dateDigitalFormatter;
|
|
9
|
+
return this.dateDigitalFormatter[timeZone+locale];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
static getDateTextFormatter(locale, timeZone) {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
this.dateTextFormatter = this.dateTextFormatter || {};
|
|
14
|
+
if (typeof this.dateTextFormatter[timeZone+locale] == 'undefined') {
|
|
15
|
+
this.dateTextFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', timeZone: timeZone });
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
return this.dateTextFormatter;
|
|
18
|
+
return this.dateTextFormatter[timeZone+locale];
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
static getDateTimeFormatter(locale, timeZone) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
this.dateTimeFormatter = this.dateTimeFormatter || {};
|
|
23
|
+
if (typeof this.dateTimeFormatter[timeZone+locale] == 'undefined') {
|
|
24
|
+
this.dateTimeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
return this.dateTimeFormatter;
|
|
27
|
+
return this.dateTimeFormatter[timeZone+locale];
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
static getDateSqlFormatter(timeZone) {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
this.dateSqlFormatter = this.dateSqlFormatter || {};
|
|
32
|
+
if (typeof this.dateSqlFormatter[timeZone] == 'undefined') {
|
|
33
|
+
this.dateSqlFormatter[timeZone] = new Intl.DateTimeFormat('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: timeZone });
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
return this.dateSqlFormatter;
|
|
36
|
+
return this.dateSqlFormatter[timeZone];
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
static getTimeSqlFormatter(timeZone) {
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
this.timeSqlFormatter = this.timeSqlFormatter || {};
|
|
41
|
+
if (typeof this.timeSqlFormatter[timeZone] == 'undefined') {
|
|
42
|
+
console.log('init getTimeSqlFormatter avec timezone', timeZone);
|
|
43
|
+
this.timeSqlFormatter[timeZone] = new Intl.DateTimeFormat('en-GB', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false, timeZone: timeZone }); //hour12: false = 24h format
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
return this.timeSqlFormatter;
|
|
46
|
+
return this.timeSqlFormatter[timeZone];
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
static getTimeFormatter(locale, timeZone) {
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
this.timeFormatter = this.timeFormatter || {};
|
|
51
|
+
if (typeof this.timeFormatter[timeZone+locale] == 'undefined') {
|
|
52
|
+
this.timeFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: 'numeric', timeZone: timeZone });
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
return this.timeFormatter;
|
|
55
|
+
return this.timeFormatter[timeZone+locale];
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
static getTimeDigitalFormatter(locale, timeZone) {
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
this.timeDigitalFormatter = this.timeDigitalFormatter || {};
|
|
60
|
+
if (typeof this.timeDigitalFormatter[timeZone+locale] == 'undefined') {
|
|
61
|
+
this.timeDigitalFormatter[timeZone+locale] = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timeZone });
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
return this.timeDigitalFormatter;
|
|
64
|
+
return this.timeDigitalFormatter[timeZone+locale];
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
67
|
|
package/http_client.js
CHANGED
|
@@ -223,27 +223,27 @@ class HTTPClient {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
if (response.ok) {
|
|
226
|
-
if (typeof successCallback
|
|
226
|
+
if (typeof successCallback == 'function') {
|
|
227
227
|
successCallback(jsonData, response);
|
|
228
228
|
}
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
if (response.status === 400 && typeof formErrorCallback
|
|
232
|
+
if (response.status === 400 && typeof formErrorCallback == 'function') {
|
|
233
233
|
formErrorCallback(jsonData, response);
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
catch (e) {
|
|
238
238
|
console.error(e);
|
|
239
|
-
if (typeof errorCallback
|
|
239
|
+
if (typeof errorCallback == 'function') {
|
|
240
240
|
errorCallback(response);
|
|
241
241
|
}
|
|
242
242
|
return;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
HTTPClient.logRequestFailure(response, jsonData);
|
|
246
|
-
if (typeof errorCallback
|
|
246
|
+
if (typeof errorCallback == 'function') {
|
|
247
247
|
errorCallback(response, jsonData);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -298,24 +298,24 @@ class HTTPClient {
|
|
|
298
298
|
|
|
299
299
|
if (response.ok) {
|
|
300
300
|
const blobData = await response.blob();
|
|
301
|
-
if (typeof successCallback
|
|
301
|
+
if (typeof successCallback == 'function') {
|
|
302
302
|
successCallback(blobData, response);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
else {
|
|
306
306
|
HTTPClient.logRequestFailure(response, null);
|
|
307
|
-
if (typeof errorCallback
|
|
307
|
+
if (typeof errorCallback == 'function') {
|
|
308
308
|
errorCallback(response);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
catch (e) {
|
|
313
313
|
console.error(e);
|
|
314
|
-
if (typeof errorCallback
|
|
314
|
+
if (typeof errorCallback == 'function') {
|
|
315
315
|
errorCallback(response);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
if (typeof completeCallback
|
|
318
|
+
if (typeof completeCallback == 'function') {
|
|
319
319
|
completeCallback(response);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
@@ -366,7 +366,7 @@ class HTTPClient {
|
|
|
366
366
|
},
|
|
367
367
|
() => {
|
|
368
368
|
JwtSession.expireSession(HTTPClient.onInvalidRefreshTokenRedirectUrl, HTTPClient.onInvalidRefreshTokenCallback);
|
|
369
|
-
if (typeof errorCallback
|
|
369
|
+
if (typeof errorCallback == 'function') {
|
|
370
370
|
errorCallback();
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -394,7 +394,7 @@ class HTTPClient {
|
|
|
394
394
|
xhr.onreadystatechange = function () {
|
|
395
395
|
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
|
|
396
396
|
let data;
|
|
397
|
-
if (formatRetour
|
|
397
|
+
if (formatRetour === 'xml') {
|
|
398
398
|
data = xhr.responseXML;
|
|
399
399
|
}
|
|
400
400
|
else {
|