]> granicus.if.org Git - php/commitdiff
- Fixed bug #43003 (Invalid timezone reported for DateTime objects constructed
authorDerick Rethans <derick@php.net>
Thu, 17 Jan 2008 19:59:00 +0000 (19:59 +0000)
committerDerick Rethans <derick@php.net>
Thu, 17 Jan 2008 19:59:00 +0000 (19:59 +0000)
  using a timestamp).

NEWS
ext/date/php_date.c
ext/date/tests/bug43003.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 34821301770994a3acc89b302d745a5774f9230b..9e96c19b84b7978b646d92eed299f17002173c3b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -79,6 +79,8 @@ PHP                                                                        NEWS
 
 - Fixed bug #43527 (DateTime created from a timestamp reports environment
   timezone). (Derick)
+- Fixed bug #43003 (Invalid timezone reported for DateTime objects constructed
+  using a timestamp). (Derick)
 - Fixed bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB). (Derick)
 - Fixed bug #43136 (possible crash on script execution timeout.
   The EG(function_state_ptr) is completely removed,
index 08f8a6ffd6533d3f4e1bc5378019c3e0c08cd11b..fe0fae275fb3277a9fb5bcb49124ec05500ae663 100644 (file)
@@ -273,6 +273,7 @@ struct _php_date_obj {
 
 struct _php_timezone_obj {
        zend_object     std;
+       int             initialized;
        int             type;
        union {
                timelib_tzinfo *tz; // TIMELIB_ZONETYPE_ID;
@@ -1632,6 +1633,7 @@ static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC)
        
        zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
        new_obj->type = old_obj->type;
+       new_obj->initialized = 1;
        switch (new_obj->type) {
                case TIMELIB_ZONETYPE_ID:
                        new_obj->tzi.tz = old_obj->tzi.tz;
@@ -2052,6 +2054,7 @@ PHP_FUNCTION(date_timezone_get)
        if (dateobj->time->is_localtime/* && dateobj->time->tz_info*/) {
                date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
                tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
+               tzobj->initialized = 1;
                tzobj->type = dateobj->time->zone_type;
                switch (dateobj->time->zone_type) {
                        case TIMELIB_ZONETYPE_ID:
@@ -2277,6 +2280,7 @@ PHP_METHOD(DateTimeZone, __construct)
                        tzobj = zend_object_store_get_object(getThis() TSRMLS_CC);
                        tzobj->type = TIMELIB_ZONETYPE_ID;
                        tzobj->tzi.tz = tzi;
+                       tzobj->initialized = 1;
                } else {
                        ZVAL_NULL(getThis());
                }
@@ -2297,7 +2301,7 @@ PHP_FUNCTION(timezone_name_get)
                RETURN_FALSE;
        }
        tzobj = (php_timezone_obj *) zend_object_store_get_object(object TSRMLS_CC);
-       DATE_CHECK_INITIALIZED(tzobj->tzi.tz, DateTimeZone);
+       DATE_CHECK_INITIALIZED(tzobj->initialized, DateTimeZone);
 
        switch (tzobj->type) {
                case TIMELIB_ZONETYPE_ID:
@@ -2360,7 +2364,7 @@ PHP_FUNCTION(timezone_offset_get)
                RETURN_FALSE;
        }
        tzobj = (php_timezone_obj *) zend_object_store_get_object(object TSRMLS_CC);
-       DATE_CHECK_INITIALIZED(tzobj->tzi.tz, DateTimeZone);
+       DATE_CHECK_INITIALIZED(tzobj->initialized, DateTimeZone);
        dateobj = (php_date_obj *) zend_object_store_get_object(dateobject TSRMLS_CC);
        DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
 
@@ -2383,7 +2387,7 @@ PHP_FUNCTION(timezone_transitions_get)
                RETURN_FALSE;
        }
        tzobj = (php_timezone_obj *) zend_object_store_get_object(object TSRMLS_CC);
-       DATE_CHECK_INITIALIZED(tzobj->tzi.tz, DateTimeZone);
+       DATE_CHECK_INITIALIZED(tzobj->initialized, DateTimeZone);
        if (tzobj->type != TIMELIB_ZONETYPE_ID) {
                RETURN_FALSE;
        }
diff --git a/ext/date/tests/bug43003.phpt b/ext/date/tests/bug43003.phpt
new file mode 100644 (file)
index 0000000..3192d55
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #43003 (Invalid timezone reported for DateTime objects constructed using a timestamp)
+--FILE--
+<?php
+$oDateTest = new DateTime("@0", new DateTimeZone(date_default_timezone_get()));
+echo $oDateTest->getTimezone()->getName().": " .  $oDateTest->format("Y-m-d H:i:s")."\n";
+
+$oDateTest->setTimezone(new DateTimeZone("UTC"));
+echo $oDateTest->getTimezone()->getName().": " .  $oDateTest->format("Y-m-d H:i:s")."\n";
+
+$oDateTest->setTimezone(new DateTimeZone(date_default_timezone_get()));
+echo $oDateTest->getTimezone()->getName().": " . $oDateTest->format("Y-m-d H:i:s")."\n";
+
+$oDateTest = new DateTime("@0");
+echo $oDateTest->getTimezone()->getName().": " .  $oDateTest->format("Y-m-d H:i:s")."\n";
+
+$oDateTest->setTimezone( new DateTimeZone(date_default_timezone_get()));
+echo $oDateTest->getTimezone()->getName().": " . $oDateTest->format("Y-m-d H:i:s")."\n";
+?>
+--EXPECT--
++00:00: 1970-01-01 00:00:00
+UTC: 1970-01-01 00:00:00
+Europe/Oslo: 1970-01-01 01:00:00
++00:00: 1970-01-01 00:00:00
+Europe/Oslo: 1970-01-01 01:00:00