Skip to content

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

@serhalp

Description

@serhalp

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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions