|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78984 DateTimeZone accepting invalid UTC timezones
Submitted: 2019-12-17 19:14 UTC Modified: 2021-08-19 15:08 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: eu+php at redrat dot com dot br Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.4.0 OS: Linux
Private report: No CVE-ID: None
 [2019-12-17 19:14 UTC] eu+php at redrat dot com dot br
Today, object \DateTimeZone accepts various timezone format in your construct. One option to instantiate this is using UTC formats like "-3" or "+5", but today UTC have only timezone between -12 and +12 and construct is accepting any number, like in test script.

Expected result if you define invalid UTC timezone is fatal error, like when you set other unknown or bad timezone, as described in php_date.c#L3484, but today this object is accepting any integer value and causes mistakes in date time operations.

Test script:

    new \DateTimeZone('-3'),
    new \DateTimeZone('+3'),
    new \DateTimeZone('+30157')

Expected result:
Fatal error: Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (+30157) in %script%

Actual result:
object(DateTimeZone)#1 (2) {
  string(6) "-03:00"
object(DateTimeZone)#2 (2) {
  string(6) "+03:00"
object(DateTimeZone)#3 (2) {
  string(9) "+30157eZ"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-17 20:24 UTC]
-Assigned To: +Assigned To: geekcom
 [2019-12-17 20:24 UTC]
-Assigned To: geekcom +Assigned To:
 [2019-12-17 23:12 UTC]
Looks like this was a feature request: #45528

Introduced via
 [2020-01-20 17:09 UTC]
-Assigned To: +Assigned To: derick
 [2020-02-20 08:06 UTC] a at b dot c dot de
"but today UTC have only timezone between -12 and +12 and construct is accepting any number"

In fixing this, remember that '+1345' is a legitimate UTC offset that is in actual use (Chatham Islands Daylight Saving).
 [2021-08-18 19:31 UTC]
This is fixed for PHP 8 and later.
 [2021-08-19 15:08 UTC]
-Status: Assigned +Status: Closed
 [2021-08-19 15:08 UTC]
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from and re-test.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Feb 04 06:05:49 2023 UTC