UNPKG

348 BPlain TextView Raw
1// A test can mock away the 'real' Date class. Capture it while we still can.
2const RealDate = Date;
3export class Timer {
4 private start!: Date;
5
6 constructor() {
7 this.reset();
8 }
9
10 public reset(): void {
11 this.start = new RealDate();
12 }
13
14 public elapsedMs(): number {
15 return new RealDate().getTime() - this.start.getTime();
16 }
17}