php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63941 Date timezone code-cleanup
Submitted: 2013-01-08 16:01 UTC Modified: 2013-01-08 19:55 UTC
From: njaguar at gmail dot com Assigned:
Status: Open Package: Performance problem
PHP Version: 5.4Git-2013-01-08 (snap) OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-01-08 16:01 UTC] 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

Patches

date_perf_patch3.txt (last revision 2013-01-08 16:02 UTC by njaguar at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-08 19:55 UTC] derick@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 20:26 UTC] njaguar at gmail dot com
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!
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:21 2019 UTC