diff --git a/CHANGELOG.md b/CHANGELOG.md index cf906b0..8a99a2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ There's a change in flash messages handling, please see #391 - Enh: added `AdminController` REST controller (MatteoF96) - Enh: added method `setUser` for LoginForm model (liviuk2) - Enh: user model emailTrim validator only if not empty #486 (liviuk2) +- Fix #461: TimeZoneHelper: don't use floats for columns that could be array keys (maxxer) ## 1.5.1 April 5, 2020 diff --git a/src/User/Helper/TimezoneHelper.php b/src/User/Helper/TimezoneHelper.php index aba5f17..7f8e9b7 100644 --- a/src/User/Helper/TimezoneHelper.php +++ b/src/User/Helper/TimezoneHelper.php @@ -36,7 +36,8 @@ class TimezoneHelper $timeZones[] = [ 'timezone' => $timeZone, 'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})", - 'offset' => $offset, + // As of PHP 8.1 array keys cannot be float. Offset is used for sorting only + 'offset' => $offset * 100, ]; } diff --git a/src/User/Validator/TimeZoneValidator.php b/src/User/Validator/TimeZoneValidator.php index 387ac83..8bb808f 100644 --- a/src/User/Validator/TimeZoneValidator.php +++ b/src/User/Validator/TimeZoneValidator.php @@ -12,6 +12,7 @@ namespace Da\User\Validator; use Da\User\Contracts\ValidatorInterface; +use DateTimeZone; class TimeZoneValidator implements ValidatorInterface { @@ -24,6 +25,6 @@ class TimeZoneValidator implements ValidatorInterface public function validate() { - return in_array($this->timezone, timezone_identifiers_list(), false); + return in_array($this->timezone, DateTimeZone::listIdentifiers(), false); } } diff --git a/tests/unit/TimeZoneTest.php b/tests/unit/TimeZoneTest.php new file mode 100644 index 0000000..b425abe --- /dev/null +++ b/tests/unit/TimeZoneTest.php @@ -0,0 +1,26 @@ +getAll(); + $this->assertTrue(in_array("Europe/Rome", ArrayHelper::getColumn($alltz, "timezone"))); + $this->assertTrue(in_array("0100", ArrayHelper::getColumn($alltz, "offset"))); + } + + // Test with minPasswordRequirements equal to an empty array (= password without requirements) + public function testTimeZoneValidator() + { + $v = Yii::createObject(TimeZoneValidator::class, ["Europe/Rome"]); + $this->assertTrue($v->validate()); + } +}