@lifeready/core 1.1.13 → 1.1.15

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.
@@ -627,7 +627,7 @@
627
627
  handleApolloError(res.errors);
628
628
  serverTime = parseInt(res.data.serverTime.timestamp, 10);
629
629
  roundtrip = end - start;
630
- this.offsetMs = serverTime - (start + roundtrip / 2);
630
+ this.offsetMs = Math.round(serverTime - (start + roundtrip / 2));
631
631
  if (!this.VERIFY_ENABLED) return [3 /*break*/, 3];
632
632
  return [4 /*yield*/, this.verifyCognito()];
633
633
  case 2:
@@ -673,6 +673,27 @@
673
673
  });
674
674
  });
675
675
  };
676
+ /**
677
+ * This is the sync version to get now. Call serverNow() first, otherwise this will print error
678
+ * because the server time offset is not known. But it will return the current time as a fallback
679
+ * so as to not introduce any crashes.
680
+ *
681
+ */
682
+ TimeService.prototype.now = function () {
683
+ if (this.offsetMs === null) {
684
+ console.error('Server time offset not known. You must await serverNow() first. Returning local clock instead.');
685
+ return Date.now();
686
+ }
687
+ else {
688
+ return Date.now() + this.offsetMs;
689
+ }
690
+ };
691
+ /**
692
+ * Calls this.now() and converts to a Date object.
693
+ */
694
+ TimeService.prototype.date = function () {
695
+ return new Date(this.now());
696
+ };
676
697
  return TimeService;
677
698
  }());
678
699
  TimeService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TimeService_Factory() { return new TimeService(i0.ɵɵinject(i4.AuthClass), i0.ɵɵinject(i1.Apollo)); }, token: TimeService, providedIn: "root" });