> const f = require('faker');
> f.seed(123)
undefined
> f.date.past()
2017-06-13T21:30:19.831Z
> f.seed(123)
undefined
> f.date.past()
2017-06-13T21:30:22.503Z
I noticed this issue then had a look at the source and turns out that you'll only get the same date if you supply a refDate parameter, which comes after the years parameter.
So you can do f.date.past(1, new Date(2018, 0, 0)) to get a date in 2017†that depends only on the seed.
†You might get the last second of 2016 or something. I haven't checked.
I ran into this issue and ended up monkeypatching the date-related methods to provide a consistent refDate when needed:
const oldPast = faker.date.past;
faker.date.past = (years = 1, refDate = new Date(2018, 0, 0)) =>
oldPast.call(faker.date, years, refDate);
Most helpful comment
I noticed this issue then had a look at the source and turns out that you'll only get the same date if you supply a refDate parameter, which comes after the years parameter.
So you can do
f.date.past(1, new Date(2018, 0, 0))to get a date in 2017†that depends only on the seed.†You might get the last second of 2016 or something. I haven't checked.