derick Sat Jul 2 17:19:25 2005 EDT Added files: /php-src/ext/date/tests timezone-configuration.phpt
Modified files: /php-src NEWS /php-src/ext/date php_date.c php_date.h /php-src/ext/date/tests bug26198.phpt bug29585.phpt default-timezone-2.phpt Log: - Overhauled selecting the correct timezone. The timezone set with "date_timezone_set" override the TZ environment variable, which on its turn overrides the date.timezone setting. If none of the three is set, we fallback to UTC. - Added "date_timezone_set" function to set the timezone that the date functions will use.
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1970&r2=1.1971&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1970 php-src/NEWS:1.1971 --- php-src/NEWS:1.1970 Thu Jun 30 18:29:36 2005 +++ php-src/NEWS Sat Jul 2 17:19:24 2005 @@ -3,6 +3,8 @@ ?? ??? 2005, PHP 5.1 Beta 3 - Upgraded bundled SQLite library for PDO:SQLite to 3.2.2 (Ilia) - Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql. (Ilia) +- Added "date_timezone_set" function to set the timezone that the date + functions will use. (Derick) - Implemented feature request #33452 (Year belonging to ISO week). (Derick) - Fixed bug #33523 (Memory leak in xmlrpc_encode_request()). (Ilia) - Fixed bug #33491 (crash after extending MySQLi internal class). (Tony) http://cvs.php.net/diff.php/php-src/ext/date/php_date.c?r1=1.19&r2=1.20&ty=u Index: php-src/ext/date/php_date.c diff -u php-src/ext/date/php_date.c:1.19 php-src/ext/date/php_date.c:1.20 --- php-src/ext/date/php_date.c:1.19 Fri Jul 1 04:59:57 2005 +++ php-src/ext/date/php_date.c Sat Jul 2 17:19:25 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.c,v 1.19 2005/07/01 08:59:57 edink Exp $ */ +/* $Id: php_date.c,v 1.20 2005/07/02 21:19:25 derick Exp $ */ #include "php.h" #include "php_streams.h" @@ -32,13 +32,15 @@ PHP_FE(date, NULL) PHP_FE(gmdate, NULL) PHP_FE(strtotime, NULL) + PHP_FE(date_timezone_set, NULL) + PHP_FE(date_timezone_get, NULL) {NULL, NULL, NULL} }; ZEND_DECLARE_MODULE_GLOBALS(date) PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("date.timezone", "GMT", PHP_INI_ALL, OnUpdateString, default_timezone, zend_date_globals, date_globals) + STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdateString, default_timezone, zend_date_globals, date_globals) PHP_INI_END() @@ -48,8 +50,8 @@ date_functions, /* function list */ PHP_MINIT(date), /* process startup */ PHP_MSHUTDOWN(date), /* process shutdown */ - NULL, /* request startup */ - NULL, /* request shutdown */ + PHP_RINIT(date), /* request startup */ + PHP_RSHUTDOWN(date), /* request shutdown */ PHP_MINFO(date), /* extension info */ PHP_VERSION, /* extension version */ STANDARD_MODULE_PROPERTIES @@ -59,9 +61,29 @@ static void php_date_init_globals(zend_date_globals *date_globals) { date_globals->default_timezone = NULL; + date_globals->timezone = NULL; } /* }}} */ +PHP_RINIT_FUNCTION(date) +{ + if (DATEG(timezone)) { + efree(DATEG(timezone)); + } + DATEG(timezone) = NULL; + + return SUCCESS; +} + +PHP_RSHUTDOWN_FUNCTION(date) +{ + if (DATEG(timezone)) { + efree(DATEG(timezone)); + } + DATEG(timezone) = NULL; + + return SUCCESS; +} PHP_MINIT_FUNCTION(date) { @@ -93,15 +115,39 @@ { char *env; + /* Checking configure timezone */ + if (DATEG(timezone) && (strlen(DATEG(timezone)) > 0)) { + return DATEG(timezone); + } + /* Check environment variable */ env = getenv("TZ"); - if (env) { + if (env && *env) { return env; } - /* Check config setting */ - if (DATEG(default_timezone)) { + /* Check config setting for default timezone */ + if (DATEG(default_timezone) && (strlen(DATEG(default_timezone)) > 0)) { return DATEG(default_timezone); } - return "GMT"; + /* Fallback to UTC */ + return "UTC"; +} + +static timelib_tzinfo *get_timezone_info(TSRMLS_D) +{ + char *tz; + timelib_tzinfo *tzi; + + tz = guess_timezone(TSRMLS_C); + tzi = timelib_parse_tzfile(tz); + if (! tzi) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Timezone setting (date.timezone) or TZ environment variable contain an unknown timezone."); + tzi = timelib_parse_tzfile("UTC"); + + if (! tzi) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Timezone database is corrupt - this should *never* happen!"); + } + } + return tzi; } /* =[ date() and gmdate() ]================================================ */ @@ -256,12 +302,7 @@ t = timelib_time_ctor(); if (localtime) { - tzi = timelib_parse_tzfile(guess_timezone(TSRMLS_C)); - if (! tzi) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find any timezone setting"); - timelib_time_dtor(t); - RETURN_FALSE; - } + tzi = get_timezone_info(TSRMLS_C); timelib_unixtime2local(t, ts, tzi); } else { tzi = NULL; @@ -312,14 +353,7 @@ timelib_time *t, *now; timelib_tzinfo *tzi; - tzi = timelib_parse_tzfile(guess_timezone(TSRMLS_C)); - if (! tzi) { - tzi = timelib_parse_tzfile("GMT"); - } - if (! tzi) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot find any timezone setting"); - RETURN_FALSE; - } + tzi = get_timezone_info(TSRMLS_C); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sl", ×, &time_len, &preset_ts) != FAILURE) { /* We have an initial timestamp */ @@ -366,6 +400,26 @@ } /* }}} */ +PHP_FUNCTION(date_timezone_set) +{ + char *zone; + int zone_len; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &zone, &zone_len) == FAILURE) { + RETURN_FALSE; + } + if (DATEG(timezone)) { + efree(DATEG(timezone)); + } + DATEG(timezone) = estrdup(zone); + RETURN_TRUE; +} + +PHP_FUNCTION(date_timezone_get) +{ + RETURN_STRING(DATEG(timezone), 0); +} + /* * Local variables: * tab-width: 4 http://cvs.php.net/diff.php/php-src/ext/date/php_date.h?r1=1.6&r2=1.7&ty=u Index: php-src/ext/date/php_date.h diff -u php-src/ext/date/php_date.h:1.6 php-src/ext/date/php_date.h:1.7 --- php-src/ext/date/php_date.h:1.6 Thu Jun 30 17:38:06 2005 +++ php-src/ext/date/php_date.h Sat Jul 2 17:19:25 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.h,v 1.6 2005/06/30 21:38:06 derick Exp $ */ +/* $Id: php_date.h,v 1.7 2005/07/02 21:19:25 derick Exp $ */ #ifndef PHP_DATE_H #define PHP_DATE_H @@ -24,16 +24,21 @@ extern zend_module_entry date_module_entry; #define phpext_date_ptr &date_module_entry -PHP_FUNCTION(strtotime); PHP_FUNCTION(date); PHP_FUNCTION(gmdate); +PHP_FUNCTION(strtotime); +PHP_FUNCTION(date_timezone_set); +PHP_FUNCTION(date_timezone_get); +PHP_RINIT_FUNCTION(date); +PHP_RSHUTDOWN_FUNCTION(date); PHP_MINIT_FUNCTION(date); PHP_MSHUTDOWN_FUNCTION(date); PHP_MINFO_FUNCTION(date); ZEND_BEGIN_MODULE_GLOBALS(date) char *default_timezone; + char *timezone; ZEND_END_MODULE_GLOBALS(date) #ifdef ZTS http://cvs.php.net/diff.php/php-src/ext/date/tests/bug26198.phpt?r1=1.2&r2=1.3&ty=u Index: php-src/ext/date/tests/bug26198.phpt diff -u php-src/ext/date/tests/bug26198.phpt:1.2 php-src/ext/date/tests/bug26198.phpt:1.3 --- php-src/ext/date/tests/bug26198.phpt:1.2 Sun Jun 19 12:13:34 2005 +++ php-src/ext/date/tests/bug26198.phpt Sat Jul 2 17:19:25 2005 @@ -2,6 +2,7 @@ Bug #26198 (strtotime handling of "M Y" and "Y M" format) --FILE-- <?php + putenv("TZ="); echo gmdate("F Y (Y-m-d H:i:s T)\n", strtotime("Oct 2001")); echo gmdate("M Y (Y-m-d H:i:s T)\n", strtotime("2001 Oct")); ?> http://cvs.php.net/diff.php/php-src/ext/date/tests/bug29585.phpt?r1=1.1&r2=1.2&ty=u Index: php-src/ext/date/tests/bug29585.phpt diff -u php-src/ext/date/tests/bug29585.phpt:1.1 php-src/ext/date/tests/bug29585.phpt:1.2 --- php-src/ext/date/tests/bug29585.phpt:1.1 Mon Jun 20 04:46:09 2005 +++ php-src/ext/date/tests/bug29585.phpt Sat Jul 2 17:19:25 2005 @@ -2,6 +2,7 @@ Bug #29585 (Support week numbers in strtotime()) --FILE-- <?php +putenv('TZ='); echo gmdate("Y-m-d H:i:s", strtotime("2004W30")); ?> http://cvs.php.net/diff.php/php-src/ext/date/tests/default-timezone-2.phpt?r1=1.2&r2=1.3&ty=u Index: php-src/ext/date/tests/default-timezone-2.phpt diff -u php-src/ext/date/tests/default-timezone-2.phpt:1.2 php-src/ext/date/tests/default-timezone-2.phpt:1.3 --- php-src/ext/date/tests/default-timezone-2.phpt:1.2 Wed Jun 29 15:00:35 2005 +++ php-src/ext/date/tests/default-timezone-2.phpt Sat Jul 2 17:19:25 2005 @@ -4,7 +4,7 @@ date.timezone=Europe/Oslo --FILE-- <?php - putenv('TZ'); // clean TZ so that it doesn't bypass the ini option + putenv('TZ='); // clean TZ so that it doesn't bypass the ini option echo strtotime("2005-06-18 22:15:44"); ?> --EXPECT-- http://cvs.php.net/co.php/php-src/ext/date/tests/timezone-configuration.phpt?r=1.1&p=1 Index: php-src/ext/date/tests/timezone-configuration.phpt +++ php-src/ext/date/tests/timezone-configuration.phpt --TEST-- timezone configuration [1] --INI-- date.timezone=GMT --FILE-- <?php putenv('TZ=Europe/Oslo'); echo strtotime("2005-06-18 22:15:44"), "\n"; putenv('TZ=Europe/London'); echo strtotime("2005-06-18 22:15:44"), "\n"; date_timezone_set('Europe/Oslo'); echo strtotime("2005-06-18 22:15:44"), "\n"; ?> --EXPECT-- 1119125744 1119129344 1119125744
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php