Merge branch 'PHP-5.5' into PHP-5.6

This commit is contained in:
Derick Rethans 2014-01-26 14:02:44 +01:00
commit 2e65908643
6 changed files with 84 additions and 12 deletions

View file

@ -92,6 +92,8 @@ int timelib_apply_localtime(timelib_time *t, unsigned int localtime);
void timelib_unixtime2gmt(timelib_time* tm, timelib_sll ts);
void timelib_unixtime2local(timelib_time *tm, timelib_sll ts);
void timelib_update_from_sse(timelib_time *tm);
void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset);
void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info);
void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz);
/* From parse_tz.c */

View file

@ -142,6 +142,12 @@ typedef struct timelib_time {
* 2 TimeZone abbreviation */
} timelib_time;
typedef struct timelib_abbr_info {
timelib_sll utc_offset;
char *abbr;
int dst;
} timelib_abbr_info;
typedef struct timelib_error_message {
int position;
char character;

View file

@ -214,6 +214,34 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
tm->have_zone = 1;
}
void timelib_set_timezone_from_offset(timelib_time *t, timelib_sll utc_offset)
{
if (t->tz_abbr) {
free(t->tz_abbr);
}
t->tz_abbr = NULL;
t->z = utc_offset;
t->have_zone = 1;
t->zone_type = TIMELIB_ZONETYPE_OFFSET;
t->dst = 0;
t->tz_info = NULL;
}
void timelib_set_timezone_from_abbr(timelib_time *t, timelib_abbr_info abbr_info)
{
if (t->tz_abbr) {
free(t->tz_abbr);
}
t->tz_abbr = strdup(abbr_info.abbr);
t->z = abbr_info.utc_offset;
t->have_zone = 1;
t->zone_type = TIMELIB_ZONETYPE_ABBR;
t->dst = abbr_info.dst;
t->tz_info = NULL;
}
void timelib_set_timezone(timelib_time *t, timelib_tzinfo *tz)
{
timelib_time_offset *gmt_offset;

View file

@ -3284,11 +3284,18 @@ static void php_date_timezone_set(zval *object, zval *timezone_object, zval *ret
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
tzobj = (php_timezone_obj *) zend_object_store_get_object(timezone_object TSRMLS_CC);
if (tzobj->type != TIMELIB_ZONETYPE_ID) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only do this for zones with ID for now");
return;
switch (tzobj->type) {
case TIMELIB_ZONETYPE_OFFSET:
timelib_set_timezone_from_offset(dateobj->time, tzobj->tzi.utc_offset);
break;
case TIMELIB_ZONETYPE_ABBR:
timelib_set_timezone_from_abbr(dateobj->time, tzobj->tzi.z);
break;
case TIMELIB_ZONETYPE_ID:
timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
break;
}
timelib_set_timezone(dateobj->time, tzobj->tzi.tz);
timelib_unixtime2local(dateobj->time, dateobj->time->sse);
}

View file

@ -137,14 +137,9 @@ struct _php_timezone_obj {
int initialized;
int type;
union {
timelib_tzinfo *tz; /* TIMELIB_ZONETYPE_ID; */
timelib_sll utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
struct /* TIMELIB_ZONETYPE_ABBR */
{
timelib_sll utc_offset;
char *abbr;
int dst;
} z;
timelib_tzinfo *tz; /* TIMELIB_ZONETYPE_ID */
timelib_sll utc_offset; /* TIMELIB_ZONETYPE_OFFSET */
timelib_abbr_info z; /* TIMELIB_ZONETYPE_ABBR */
} tzi;
HashTable *props;
};

View file

@ -0,0 +1,34 @@
--TEST--
Test for bug #45543: DateTime::setTimezone can not set timezones without ID.
--INI--
date.timezone=UTC
--FILE--
<?php
$test_dates = array(
'2008-01-01 12:00:00 PDT',
'2008-01-01 12:00:00 +02:00',
);
foreach ($test_dates as $test_date)
{
$d1 = new DateTime($test_date);
$d2 = new DateTime('2008-01-01 12:00:00 UTC');
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
$tz = $d1->getTimeZone();
$d2->setTimeZone($tz);
echo $d1->format(DATE_ISO8601), PHP_EOL;
echo $d2->format(DATE_ISO8601), PHP_EOL;
echo PHP_EOL;
}
--EXPECT--
2008-01-01T12:00:00-0700
2008-01-01T12:00:00+0000
2008-01-01T12:00:00-0700
2008-01-01T05:00:00-0700
2008-01-01T12:00:00+0200
2008-01-01T12:00:00+0000
2008-01-01T12:00:00+0200
2008-01-01T14:00:00+0200