Skip to content

DateTimeZone fails to parse time zones that contain the "+" character #10218

Closed
@spideyfusion

Description

@spideyfusion

Description

The following code:

<?php
var_dump(new DateTime('now', new DateTimeZone('Etc/GMT+1')));

Resulted in this output:

Fatal error: Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/GMT+1) in /in/bGhje:3
Stack trace:
#0 /in/bGhje(3): DateTimeZone->__construct('Etc/GMT+1')
#1 {main}
  thrown in /in/bGhje on line 3

But I expected this output instead:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2023-01-04 12:37:42.004396"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(9) "Etc/GMT+1"
}

3v4l.org link: https://3v4l.org/bGhje#v8.2.1


Looks like it broke after the latest timelib update. Looking through the recent changes, it seems that the + character is not considered in this lookup function.

@derickr Could you take a look at this?

PHP Version

PHP 8.2.1 RC1

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions