Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fake.futureDate() and fake.pastDate() #78

Open
serhalp opened this issue Jan 11, 2021 · 0 comments
Open

Add fake.futureDate() and fake.pastDate() #78

serhalp opened this issue Jan 11, 2021 · 0 comments

Comments

@serhalp
Copy link
Contributor

serhalp commented Jan 11, 2021

Occasionally we have a need to generate a date where the only requirement is that it be in the past or in the future. This requires a bit of inexpressive boilerplate each time.

This proposes to add:

  • fake.futureDate(): generates a JavaScript Date later than Date.now()
  • fake.pastDate(): generates a JavaScript Date earlier than Date.now()

Alternatively, we could nest these under fake.date.{future,past}? But that would require either making a breaking API change to fake.date() or doing that weird pattern where fake.date is simultaneously a function and an object, which I'm not a fan of.

(Ideally, it would be cool to validate somehow that when these two methods are used, the clock is stubbed, since such a thing should never be used with nondeterministic, actual clock time, but that sounds like something that would be a nightmare to implement since we'd have to make some hacky assumptions about stubbing libraries, etc. It probably isn't worth it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant