Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timezone() does not respect country code #606

Closed
jefhar opened this issue Feb 25, 2023 · 2 comments · Fixed by #607
Closed

timezone() does not respect country code #606

jefhar opened this issue Feb 25, 2023 · 2 comments · Fixed by #607

Comments

@jefhar
Copy link

jefhar commented Feb 25, 2023

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
@pimjansen
Copy link

What is fake()? Please report a valid standalone usecase of Faker

@jefhar
Copy link
Author

jefhar commented Feb 27, 2023

@pimjansen:

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants