fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.8k stars 3.57k forks source link

[BUG] dateTimeThisYear method does not generate a properly date with current year #2027

Open didix16 opened 3 years ago

didix16 commented 3 years ago

Summary

Hi, like title says, I'm using the method dateTimeThisYear() to generate a date from current year but, sometimes is generating a date from previous year!

Versions

Version
PHP 7.4.5
fzaninotto/faker ^1.4

Self-enclosed code snippet for reproduction

for($i = 0; $i < 100; $i++) {
    $y = $faker->dateTimeThisYear()->format("Y");

    if ($y != "2020") {
        throw new \Exception("FAKER ERROR. Generated year: ". $y);
    }
}

Expected output

It should not generate an Exception.

Actual output

FAKER ERROR. Generated year: 2019