Edit report at https://bugs.php.net/bug.php?id=63941&edit=1
ID: 63941 Comment by: njaguar at gmail dot com Reported by: njaguar at gmail dot com Summary: Date timezone code-cleanup Status: Open Type: Bug Package: Performance problem Operating System: * PHP Version: 5.4Git-2013-01-08 (snap) Block user comment: N Private report: N New Comment: This patch is a minor performance increase, as well as code cleanup. This applies changes to no longer require the usage of the int value that was caching whether timezones were previously verified, as well as combining usage into just *timezone instead of using both *timezone and *default_timezone for selecting between runtime and ini values. It also replaces a strlen() check with a ptr deference to speed up validation of *timezone checks (runtime cached timezone value that is verified valid). It significantly simplifies guess_timezone(). I also removed the extraneous DATEG(timezone) = NULL from the default timezone setter function, as immediately following it, it sets to the estrndup() value that the user provided. This concept was suggested by Nuno Lopes and Christopher Jones, whom asked me to write up this patch. Thanks! Previous Comments: ------------------------------------------------------------------------ [2013-01-08 19:55:09] der...@php.net What does this patch actually do? There is a lot of weirdness in it, and I thought the performance patch was already committed? ------------------------------------------------------------------------ [2013-01-08 16:01:53] njaguar at gmail dot com Description: ------------ Per discussion with suggestions from Nuno Lopes, did some code cleanup over bug/patch https://bugs.php.net/bug.php?id=63699 Removed int for checked timezone, and also opting for a singular variable (timzeone) that is checked and set as appropriate. Simplifies code guess_timezone(). Minor speed increases (due to less if/checks from original code): date : 1.143 sec strftime : 0.961 sec strtotime : 2.166 sec (also re: Christopher Jones) Test script: --------------- <?php // test script to verify all is working as intended, and throws errors accordingly. Change php.ini date.timezone value to invalid setting to test that ed(); ini_set('date.timezone', 'FAKE_TIMEZONE'); ed(); ini_set('date.timezone', 'America/Chicago'); ed(); date_default_timezone_set('FAKE_TIMEZONE'); ed(); date_default_timezone_set('America/Los_Angeles'); ed(); function ed() { echo date('F j, Y, g:i a : e') . ' : ' . date_default_timezone_get() .' : ' . ini_get('date.timezone') ."<br>\n"; } ?> Expected result: ---------------- > php ~paul/test_date.php January 8, 2013, 9:58 am : America/Chicago : America/Chicago : America/Chicago<br> PHP Warning: ini_set(): Invalid date.timezone value 'FAKE_TIMEZONE'. in /home/paul/test_date.php on line 5 Warning: ini_set(): Invalid date.timezone value 'FAKE_TIMEZONE'. in /home/paul/test_date.php on line 5 January 8, 2013, 9:58 am : America/Chicago : America/Chicago : FAKE_TIMEZONE<br> January 8, 2013, 9:58 am : America/Chicago : America/Chicago : America/Chicago<br> PHP Notice: date_default_timezone_set(): Timezone ID 'FAKE_TIMEZONE' is invalid in /home/paul/test_date.php on line 11 Notice: date_default_timezone_set(): Timezone ID 'FAKE_TIMEZONE' is invalid in /home/paul/test_date.php on line 11 January 8, 2013, 9:58 am : America/Chicago : America/Chicago : America/Chicago<br> January 8, 2013, 7:58 am : America/Los_Angeles : America/Los_Angeles : America/Chicago<br> Actual result: -------------- n/a ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63941&edit=1