From 3552841302537e890f9e9450c02968e609d3b1cd Mon Sep 17 00:00:00 2001 From: Jeff Harris Date: Sat, 25 Feb 2023 00:29:59 -0500 Subject: [PATCH 1/2] Replicate missing functionality. https://github.com/FakerPHP/Faker/pull/480/files added optional countryCode parameter, to Core and Extension classes, but not the Provider class. --- src/Faker/Provider/DateTime.php | 11 +++++++++-- test/Faker/Provider/DateTimeTest.php | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Faker/Provider/DateTime.php b/src/Faker/Provider/DateTime.php index 46c3c90fec..44c5a5b0f8 100644 --- a/src/Faker/Provider/DateTime.php +++ b/src/Faker/Provider/DateTime.php @@ -330,13 +330,20 @@ public static function century() } /** + * @param string|null $countryCode * @return string * * @example 'Europe/Paris' */ - public static function timezone() + public static function timezone(string $countryCode = null) { - return static::randomElement(\DateTimeZone::listIdentifiers()); + if ($countryCode) { + $timezones = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $countryCode); + } else { + $timezones = \DateTimeZone::listIdentifiers(); + } + + return static::randomElement($timezones); } /** diff --git a/test/Faker/Provider/DateTimeTest.php b/test/Faker/Provider/DateTimeTest.php index 5b0ce2bdf6..0dc446c648 100644 --- a/test/Faker/Provider/DateTimeTest.php +++ b/test/Faker/Provider/DateTimeTest.php @@ -281,4 +281,15 @@ public function testFixedSeedWithMaximumTimestamp(): void self::assertEquals($dateTimeThisYear, DateTimeProvider::dateTimeThisYear($max)); mt_srand(); } + + public function testTimezone(): void + { + $timezone = DateTimeProvider::timezone(); + $countryTimezone = DateTimeProvider::timezone('US'); + + self::assertIsString($timezone); + self::assertContains($timezone, \DateTimeZone::listIdentifiers()); + self::assertIsString($countryTimezone); + self::assertContains($countryTimezone, \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, 'US')); + } } From ecb055ef32dd4d591c28b71d469640428cf13e01 Mon Sep 17 00:00:00 2001 From: Jeff Harris Date: Wed, 8 Mar 2023 15:59:58 -0500 Subject: [PATCH 2/2] remove line. --- src/Faker/Provider/DateTime.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Faker/Provider/DateTime.php b/src/Faker/Provider/DateTime.php index 44c5a5b0f8..25df1c9928 100644 --- a/src/Faker/Provider/DateTime.php +++ b/src/Faker/Provider/DateTime.php @@ -330,7 +330,6 @@ public static function century() } /** - * @param string|null $countryCode * @return string * * @example 'Europe/Paris'