Req #45528 [Com]: Cannot initialize a DateTimeZone object by offset only

From: Date: Sun, 30 Mar 2014 19:45:12 +0000
Subject: Req #45528 [Com]: Cannot initialize a DateTimeZone object by offset only
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184965@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=45528&edit=1

 ID:                 45528
 Comment by:         evert at rooftopsolutions dot nl
 Reported by:        tj at systisoft dot com
 Summary:            Cannot initialize a DateTimeZone object by offset
                     only
 Status:             Closed
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   All
 PHP Version:        5.3CVS-2008-07-16 (CVS)
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

Welp.. this was pretty much a BC break. PHP 5.5.10 broke 5 unittests for me.


Previous Comments:
------------------------------------------------------------------------
[2014-02-09 20:59:01] derick@php.net

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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------
[2008-07-16 09:58:17] tj at systisoft dot com

Description:
------------
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:
----------------
+01:00

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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=45528&edit=1


Thread (4 messages)

« previous php.bugs (#184965) next »