| 7 | }; |
| 8 | |
| 9 | export class PreciseWallClock implements Clock { |
| 10 | private _origin: { |
| 11 | clockTime: ClockTime; |
| 12 | preciseDate: PreciseDate; |
| 13 | }; |
| 14 | |
| 15 | get #originClockTime() { |
| 16 | return this._origin.clockTime; |
| 17 | } |
| 18 | |
| 19 | get #originPreciseDate() { |
| 20 | return this._origin.preciseDate; |
| 21 | } |
| 22 | |
| 23 | constructor(options: PreciseWallClockOptions = {}) { |
| 24 | this._origin = { |
| 25 | clockTime: options.origin ?? process.hrtime(), |
| 26 | preciseDate: options.now ?? new PreciseDate(), |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | preciseNow(): [number, number] { |
| 31 | const elapsedHrTime = process.hrtime(this.#originClockTime); |
| 32 | const elapsedNanoseconds = BigInt(elapsedHrTime[0]) * BigInt(1e9) + BigInt(elapsedHrTime[1]); |
| 33 | |
| 34 | const preciseDate = new PreciseDate(this.#originPreciseDate.getFullTime() + elapsedNanoseconds); |
| 35 | const dateStruct = preciseDate.toStruct(); |
| 36 | |
| 37 | return [dateStruct.seconds, dateStruct.nanos]; |
| 38 | } |
| 39 | |
| 40 | reset() { |
| 41 | this._origin = { |
| 42 | clockTime: process.hrtime(), |
| 43 | preciseDate: new PreciseDate(), |
| 44 | }; |
| 45 | } |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…