FakerPHP / Faker

Faker is a PHP library that generates fake data for you
https://fakerphp.github.io
Other
3.47k stars 330 forks source link

date/datetime functions not consistently seedable #874

Closed solakram closed 3 months ago

solakram commented 3 months ago

Summary

If the faker is seeded, the date/datetime functions can return inconsistent values depending on the date the current machine is running on.

this means, running a seeded the fake()->date will return different results every day.

this behaviour can be fixed if you set the $max parameter: fake()->date('Y-m-d', '2024-01-01') however, i think a seeded faker should take care of this by its own

Versions

Version
PHP 8.2.11
fakerphp/faker v1.23.1

Self-enclosed code snippet for reproduction

fake()->seed(123);
for ($i = 1; $i <= 3; $i++) {
    echo fake()->date() . PHP_EOL;
}

Expected output

the outputs should always be the same, independent on what the current date of the local machine is.
f.e.
1986-04-13
1985-04-08
2008-12-11

Actual output

outputs on local machine date 2024-03-21:
1986-04-12
1985-04-07
2008-12-08

outputs on local machine date 2024-03-25:
1986-04-13
1985-04-08
2008-12-11
pimjansen commented 3 months ago

That is your opinion. As mentioned in the docs it works like expected when you provide the max value. If not the current date is used if i recall correctly