Timezone fixes for php 8.1 (#490)

* Added simple test for TimeZoneHelper #461
* TimeZone offset: don't use float values for columns that could be array keys #461
This commit is contained in:
Lorenzo Milesi
2022-12-29 10:55:01 +01:00
committed by GitHub
parent 44936aacc3
commit d19374afec
4 changed files with 31 additions and 2 deletions

View File

@ -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,
];
}

View File

@ -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);
}
}