Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Kz faker random wrong output from getCenturyByYear #2025

Open
maris-liepins-ermac opened this issue Jul 9, 2020 · 0 comments
Open

Kz faker random wrong output from getCenturyByYear #2025

maris-liepins-ermac opened this issue Jul 9, 2020 · 0 comments

Comments

@maris-liepins-ermac
Copy link

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant