|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45528 Cannot initialize a DateTimeZone object by offset only
Submitted: 2008-07-16 09:58 UTC Modified: 2014-02-09 20:59 UTC
Avg. Score:4.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:4 (80.0%)
From: tj at systisoft dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3CVS-2008-07-16 (CVS) OS: All
Private report: No CVE-ID: None
 [2008-07-16 09:58 UTC] tj at systisoft dot com
Sometimes you get timezones from other sources in offset only format. This is often the case when dealing with databases.

So yo have sometimes the situation where you have to set a time zone to a DateTime that is only defined by the offset. While an offset alone is not a time zone the DateTimeZone object can handle them by treating them as a time zone without daylight saving and offset, the name of that time zone is the offset itself. This seems to be the way if such time zones are obtained from a DateTime object. 

It would be nice behavior if new DateTimeZone($d->getName()) will always succeed if $d is a DateTimeZone.

Reproduce code:
$d = new DateTimeZone(date_create('+01:00')->getTimeZone()->getName());
echo $d->getName();

Expected result:

Actual result:
PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTimeZone::__construct(): Unknown or bad timezone (+01:00)' in Command line code:1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 14:25 UTC]
-Package: Feature/Change Request +Package: Date/time related
 [2010-12-20 14:25 UTC]
-Summary: You cannot initialize a DateTimeZone object by offset only. +Summary: Cannot initialize a DateTimeZone object by offset only
 [2014-02-09 20:59 UTC]
-Status: Assigned +Status: Closed
 [2014-02-09 20:59 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2014-03-30 19:45 UTC] evert at rooftopsolutions dot nl
Welp.. this was pretty much a BC break. PHP 5.5.10 broke 5 unittests for me.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 10:03:43 2023 UTC