fzaninotto/Faker

Kz faker random wrong output from getCenturyByYear

maris-liepins-ermac opened this issue · 0 comments

Summary

If $year is set to 2001, there is a chance that DateTime::year() will return value less than 2000, which will cause a bug and instead of 21st century will return 20th century. DateTime::year() returns random value.

Versions

Version
PHP 7.4.0
fzaninotto/faker 1.9.1

Self-enclosed code snippet for reproduction

    private static function getCenturyByYear($year)
    {
        if ($year >= 2000 && $year <= DateTime::year()) {
            return self::CENTURY_21ST;
        } elseif ($year >= 1900) {
            return self::CENTURY_20TH;
        } elseif ($year >= 1800) {
            return self::CENTURY_19TH;
        }
    }

Expected output

use Faker\Provider\kk_KZ\Person;

$date = DateTime::year(); // 2020
$value = Person::getCenturyByYear(2001);
// expected Person::CENTURY_21ST

Actual output

use Faker\Provider\kk_KZ\Person;

$date = DateTime::year(); // 1970
$value = Person::getCenturyByYear(2001);
// actual Person::CENTURY_20TH