Options
All
  • Public
  • Public/Protected
  • All
Menu

A SynchronizedClock allows for approximating the time on a remote machine.

During initialization, a known time of the remote host must be supplied. Once the remote time is known, this class can approximate the time on the remote machine from a date or duration.

example
const knownRemoteTime = await getRemoteTime();
const clock = new SynchronizedClock(knownRemoteTime);

const localDate = new Date();
const serverTime = clock.remoteTime(localDate);

const remoteDate = await getRemoteTime();
const localTime = clock.localTime(remoteDate);

const currentRemoteTime = clock.remoteNow();

Hierarchy

  • SynchronizedClock

Index

Constructors

  • new SynchronizedClock(knownRemoteTime: Date, knownLocalTime?: Date): SynchronizedClock

Properties

knownLocalTime: Date = ...
knownRemoteTime: Date

Methods

  • localOffset(): number
  • localTime(remoteTime: Date): Date
  • localTime(remoteDurationInMs: number): Date
  • remoteNow(): Date
  • remoteOffset(localTime?: Date): number
  • remoteTime(localTime: Date): Date
  • remoteTime(localDurationInMs: number): Date