Skip to content

past/future date functions to support min years #3653

@karlismelderis-mckinsey

Description

@karlismelderis-mckinsey

Clear and concise description of the problem

currently past and future supports only option to set max range in years
In case test needs short date in past/future (.toISOString().slice(0, 10) magic 🪄) you can still get date of current day

Suggested solution

to avoid adjusting reference date or manually adding +/- days it would be nice to support additional config to set min diff

e.g.

faker.date.past({yearsMin: 1, years: 2}) // at least 1 year but not more than 2 years in the past

faker.date.future({yearsMin: 1, years: 2}) // at least 1 year but not more than 2 years in the future

I guess same would apply for soon and recent

Alternative

I can use date-fns to add/remove random number of days but it feels bit to ugly

addDays(
          new Date(),
          faker.number.int({ min: 1, max: 20 }),
        )
          .toISOString()
          .slice(0, 10)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions