Created
June 2, 2020 19:11
-
-
Save calexandrepcjr/aa181c6f30a371e2b7d6d47f0e6d07fc to your computer and use it in GitHub Desktop.
Helps testing some routines regarding time, freezing dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class DateFreeze { | |
private readonly originalNow: () => number = Date.now.bind(Date); | |
public constructor(private timestamp: number) {} | |
public freeze(timestamp?: number): this { | |
if (timestamp !== undefined) { | |
this.timestamp = timestamp; | |
} | |
Date.now = () => this.timestamp; | |
return this; | |
} | |
public unfreeze(): this { | |
Date.now = this.originalNow; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment