timezone() does not respect country code
jefhar opened this issue · comments
Jeff Harris commented
Summary
Faker\Provider\DateTime::timezone()
is missing the optional $countryCode
that is found in Faker\Core\DateTime::timezone()
.
This has the effect (in Laravel anyway) that fake()->timezone('US')
provides a random timezone instead of returning a timezone in the designated country code.
Versions
Version | |
---|---|
PHP | 8.2 |
fakerphp/faker |
1.21.0 |
Self-enclosed code snippet for reproduction
fake()->timezone('US');
Expected output
"America/Indiana/Knox"
Actual output
Africa/Algiers
Pim Jansen commented
What is fake()? Please report a valid standalone usecase of Faker
Jeff Harris commented
index.php consists of
<?php
require_once './vendor/autoload.php';
$countryCode = 'US';
$faker = new \Faker\Provider\DateTime(new \Faker\Generator());
echo 'This timezone should be in ' . $countryCode. ': `' . $faker::timezone($countryCode) . '`' . PHP_EOL;
composer.json consists of
{
"require": {
"fakerphp/faker": "^1.21"
}
}
Output:
$ php index.php
This timezone should be in US: `America/Cuiaba`
$ php index.php
This timezone should be in US: `Europe/Istanbul`
$ php index.php
This timezone should be in US: `Australia/Perth`
$ php index.php
This timezone should be in US: `America/St_Vincent`
$ php index.php
This timezone should be in US: `America/Argentina/Rio_Gallegos`
$ php index.php
This timezone should be in US: `Antarctica/Davis`
$ php index.php
This timezone should be in US: `America/Monterrey`
Change composer.json to
{
"require": {
"fakerphp/faker": "dev-jefhar/bugfix-country-timezones"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jefhar/Faker"
}
]
}
Output:
$ php index.php
This timezone should be in US: `America/Nome`
$ php index.php
This timezone should be in US: `America/North_Dakota/Center`
$ php index.php
This timezone should be in US: `America/Denver`
$ php index.php
This timezone should be in US: `America/Boise`
$ php index.php
This timezone should be in US: `America/Sitka`
$ php index.php
This timezone should be in US: `America/New_York`
$ php index.php
This timezone should be in US: `America/Indiana/Tell_City`