@osimatic/helpers-js 1.1.43 → 1.1.45

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/CHANGELOG CHANGED
@@ -66,3 +66,6 @@ var serviceCountry = 'XX' -> TelephoneNumber.setLocalCountryCode('XX')
66
66
 
67
67
  1.1.28
68
68
  ImportFromCsv.initModal() -> ImportFromCsv.initForm()
69
+
70
+ 1.1.44
71
+ Toutes les fonctions des classes SqlTime, SqlDate et SqlDateTime prennent maintenant les dates et heures SQL en UTC. CECI EST TRES IMPORTANT SINON CELA FAUSSE LES DATES/HEURES SELON LES FUSEAUX HORAIRES.
package/date_time.js CHANGED
@@ -390,12 +390,15 @@ class TimestampUnix {
390
390
 
391
391
  }
392
392
 
393
+ /**
394
+ * Les dates SQL fournies en paramètre doivent être en UTC.
395
+ */
393
396
  class SqlDate {
394
397
  static parse(sqlDate) {
395
398
  if (sqlDate == null) {
396
399
  return null;
397
400
  }
398
- return new Date(sqlDate.substring(0, 4), sqlDate.substring(5, 7)-1, sqlDate.substring(8, 10), 0, 0, 0);
401
+ return new Date(Date.UTC(sqlDate.substring(0, 4), sqlDate.substring(5, 7)-1, sqlDate.substring(8, 10), 0, 0, 0));
399
402
  }
400
403
 
401
404
  static getCurrentSqlDate() {
@@ -413,6 +416,10 @@ class SqlDate {
413
416
  return SqlDateTime.getDateForInputDate(sqlDate+" 00:00:00", timeZone);
414
417
  }
415
418
 
419
+ static getTimestamp(sqlDate) {
420
+ return SqlDateTime.getTimestamp(sqlDate+" 00:00:00");
421
+ }
422
+
416
423
  static getYear(sqlDate) {
417
424
  return SqlDateTime.getYear(sqlDate+" 00:00:00");
418
425
  }
@@ -432,6 +439,9 @@ class SqlDate {
432
439
 
433
440
  }
434
441
 
442
+ /**
443
+ * Les heures SQL fournies en paramètre doivent être en UTC.
444
+ */
435
445
  class SqlTime {
436
446
  static parse(sqlTime) {
437
447
  if (sqlTime == null) {
@@ -441,10 +451,14 @@ class SqlTime {
441
451
  if ((sqlTime.match(/\:/g) || []).length == 1) {
442
452
  sqlTime += ':00';
443
453
  }
444
- let jsDate = new Date();
454
+
445
455
  let arrayTime = sqlTime.split(':');
446
- jsDate.setHours(arrayTime[0], arrayTime[1], arrayTime[2], 0);
447
- return jsDate;
456
+ return new Date(Date.UTC(1970, 0, 1, arrayTime[0], arrayTime[1], arrayTime[2]));
457
+
458
+ /*let jsDate = new Date();
459
+ jsDate.setUTCFullYear(1970, 0, 1);
460
+ jsDate.setUTCHours(arrayTime[0], arrayTime[1], arrayTime[2], 0);
461
+ return jsDate;*/
448
462
  }
449
463
 
450
464
  static getCurrentSqlTime() {
@@ -464,8 +478,16 @@ class SqlTime {
464
478
  static getTimeForInputTime(sqlTime, timeZone="Europe/Paris", withSeconds=false) {
465
479
  return SqlDateTime.getTimeForInputTime('1970-01-01 '+sqlTime, timeZone, withSeconds);
466
480
  }
481
+
482
+ static getTimestamp(sqlTime) {
483
+ return SqlDateTime.getTimestamp('1970-01-01 '+sqlTime);
484
+ }
485
+
467
486
  }
468
487
 
488
+ /**
489
+ * Les dates/heures SQL fournies en paramètre doivent être en UTC.
490
+ */
469
491
  class SqlDateTime {
470
492
  static getCurrentSqlDateTime() {
471
493
  return DateTime.getSqlDateTime(new Date());
@@ -489,7 +511,8 @@ class SqlDateTime {
489
511
  if (sqlDateTime == null) {
490
512
  return null;
491
513
  }
492
- return new Date(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19));
514
+ //return new Date(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19));
515
+ return new Date(Date.UTC(sqlDateTime.substring(0, 4), sqlDateTime.substring(5, 7)-1, sqlDateTime.substring(8, 10), sqlDateTime.substring(11, 13), sqlDateTime.substring(14, 16), sqlDateTime.substring(17, 19)));
493
516
  }
494
517
 
495
518
  static getDateDigitalDisplay(sqlDateTime, locale="fr-FR", timeZone="Europe/Paris") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.1.43",
3
+ "version": "1.1.45",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"