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

DateTimeZone::listIdentifiers returns a timezone Etc/GMT+0 which can not be used by DateTimeZone constructor #10287

Closed
fuzin opened this issue Jan 11, 2023 · 5 comments

Comments

@fuzin
Copy link

fuzin commented Jan 11, 2023

Description

The following code:

<?php

$timezoneIdentifiers = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC);

foreach($timezoneIdentifiers as $timezoneIdentifier) {
    (new \DateTimeZone($timezoneIdentifier));
}

Resulted in this output:

PHP Fatal error:  Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/GMT+0)

But I expect if DateTimeZone::getIdentifiers retuns a timezone it is also possible to use it in constructor.

It is working fine in PHP 8.2.0.

PHP Version

PHP 8.2.1

Operating System

php:8.2-fpm-alpine

@heiglandreas
Copy link
Contributor

This is a duplicate of #10218

@fuzin
Copy link
Author

fuzin commented Jan 11, 2023

Thnx @heiglandreas for quick answer.

This works fine:

<?php

$timezoneIdentifiers = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC);

foreach($timezoneIdentifiers as $timezoneIdentifier) {

    if (in_array($timezoneIdentifier, [
        'Etc/GMT+0',
        'Etc/GMT+1',
        'Etc/GMT+2',
        'Etc/GMT+3',
        'Etc/GMT+4',
        'Etc/GMT+5',
        'Etc/GMT+6',
        'Etc/GMT+7',
        'Etc/GMT+8',
        'Etc/GMT+9',
        'Etc/GMT+10',
        'Etc/GMT+11',
        'Etc/GMT+12'
    ])) continue;

    (new \DateTimeZone($timezoneIdentifier));
}

We will avoid using this timezones: https://www.php.net/manual/en/timezones.others.php and since it is duplicate I am closing this issue.

It would be nice those won't be returned with listIdentifiers though.

@fuzin fuzin closed this as completed Jan 11, 2023
@heiglandreas
Copy link
Contributor

Well... When you are requesting ALL identifiers, also the ones for BackwardsCompatibility, then you should not wonder, that ALL identifiers including the ones for backwards compatibility are returned...

You should by now only use the identifiers that are returned by DateTimeZone::listIdentifiers()

@cmb69 cmb69 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2023
@fuzin
Copy link
Author

fuzin commented Jan 13, 2023

This seems to be fixed: #10297 (comment)

@Zenexer
Copy link

Zenexer commented Jan 23, 2023

@heiglandreas Then what's the point of ALL_WITH_BC? It's returning identifiers that aren't actually considered valid. I think we can all agree that this code shouldn't fail: https://3v4l.org/HMcFD Any identifier returned by listIdentifiers should be valid during the current run, assuming nothing else on the system changes while the script is running.

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

No branches or pull requests

4 participants