@osimatic/helpers-js 1.4.21 → 1.4.23

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 CHANGED
@@ -298,6 +298,16 @@ class DateTime {
298
298
  }
299
299
 
300
300
  class DatePeriod {
301
+ static isSameDay(jsDate1, jsDate2) {
302
+ return jsDate1.getFullYear() === jsDate2.getFullYear() &&
303
+ jsDate1.getMonth() === jsDate2.getMonth() &&
304
+ jsDate1.getDate() === jsDate2.getDate();
305
+ }
306
+
307
+ static isHalfDay(partOfDay) {
308
+ return partOfDay === DatePeriod.PART_OF_DAY_MORNING || partOfDay === DatePeriod.PART_OF_DAY_AFTERNOON;
309
+ }
310
+
301
311
  static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod=false, timeZone="Europe/Paris") {
302
312
  //jsDate1.set
303
313
  if (jsDate1 == null || jsDate2 == null) {
@@ -627,4 +637,9 @@ class SqlDateTime {
627
637
 
628
638
  }
629
639
 
640
+ // Part of day
641
+ DatePeriod.PART_OF_DAY_MORNING = 'MORNING';
642
+ DatePeriod.PART_OF_DAY_AFTERNOON = 'AFTERNOON';
643
+
644
+
630
645
  module.exports = { DateTime, DatePeriod, TimestampUnix, SqlDate, SqlTime, SqlDateTime };
package/http_client.js CHANGED
@@ -289,7 +289,14 @@ class HTTPClient {
289
289
 
290
290
  static download(method, url, data, errorCallback=null, completeCallback=null, additionalHeaders={}) {
291
291
  HTTPClient.requestBlob(method, url, data,
292
- (blobData, response) => File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition')),
292
+ (blobData, response) => {
293
+ const contentType = response.headers.get('content-type');
294
+ // Si la réponse est du JSON, on ne télécharge pas de fichier
295
+ if (contentType && contentType.includes('application/json')) {
296
+ return;
297
+ }
298
+ File.download(blobData, contentType, response.headers.get('content-disposition'));
299
+ },
293
300
  errorCallback,
294
301
  completeCallback,
295
302
  additionalHeaders
@@ -346,9 +353,17 @@ class HTTPClient {
346
353
  }
347
354
 
348
355
  if (response.ok) {
349
- const blobData = await response.blob();
350
- if (typeof successCallback == 'function') {
351
- successCallback(blobData, response);
356
+ if (response.headers.get('Content-Type') === 'application/json') {
357
+ const json = await response.json();
358
+ if (typeof successCallback == 'function') {
359
+ successCallback(json, response);
360
+ }
361
+ }
362
+ else {
363
+ const blobData = await response.blob();
364
+ if (typeof successCallback == 'function') {
365
+ successCallback(blobData, response);
366
+ }
352
367
  }
353
368
  }
354
369
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.21",
3
+ "version": "1.4.23",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"