Edit report at https://bugs.php.net/bug.php?id=65201&edit=1

 ID:                 65201
 Comment by:         mail+php at requinix dot net
 Reported by:        easysurf at easysurf dot cc
 Summary:            Africa/Cairo time off by 1 hour
 Status:             Open
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   Window 8
 PHP Version:        5.5.0
 Block user comment: N
 Private report:     N

 New Comment:

Windows/PHP 5.3.26 CLI:
ab's code:
- putenv() not respected, outputs default (local) time with timezone warnings
  (getenv() says Cairo, $_ENV says nothing)
- manually setting it with "set TZ=Africa/Cairo" on the command line before
  executing works
  (getenv() and $_ENV say Cairo)
- date_default_timezone_set() instead works
easysurf's code:
- outputs default (local) time with timezone warnings

Ubuntu/PHP 5.3.10:
ab's code:
- putenv() works
- date_default_timezone_set() works
easysurf's code:
- outputs local+2h with timezone warnings

The code does have a bug as ab saw:
1. Grabs the current time as a string according to the current timezone
2. Interprets the string according to the GMT timezone and gets a timestamp
3. Uses the timestamp to output the time in Cairo
Net effect is adding 2 hours (Cairo minus GMT) to the current time.
Fix: don't do anything at all with GMT and use date_default_timezone_set() 
instead 
of putenv(TZ). Like literally

<?php
date_default_timezone_set($city2);
echo date("l g:i A")."\n";
?>

All that aside, 5.3 is now EOL and 5.4+ doesn't use TZ.


Previous Comments:
------------------------------------------------------------------------
[2013-07-07 08:17:23] a...@php.net

Typing 'time in cairo' into google will show you the same. Anyway, lets see if 
someone else can reproduce the behavior you describe.

------------------------------------------------------------------------
[2013-07-06 21:27:02] easysurf at easysurf dot cc

<?php
putenv('TZ=Africa/Cairo');
echo date('l g:i A');
?>

The problem is that your site that sends out the time zone for Africa/Cairo is 
off by an hour.

When I tried the above code it is still one hour off.

Goto:
http://wwp.greenwichmeantime.com/time-zone/africa/egypt/cairo/

You will see that there is a discrepancy between your time and theirs.

Also when I watch CNN with a live feed from Cairo with a timestamp, it does not 
match you time but does match the time that Greenwich sends out.

------------------------------------------------------------------------
[2013-07-06 09:17:19] a...@php.net

I'm not sure what you're trying to do in that script, but i suppose it's a bug 
in 
it. You convert from local to GMT and then again. I cannot repro neither with 
your 
script nor with a much smaller sample

putenv('TZ=Africa/Cairo');
echo date('l g:i A');

Do that two lines work for you?

------------------------------------------------------------------------
[2013-07-06 02:08:21] easysurf at easysurf dot cc

<?php

function recity($anycity) {

$lcity1 = strlen($anycity);
$pos1 = strpos($anycity, "/");
$pos1 = $pos1 + 1;
$sstrt1 = $lcity1 - $pos1;
$tncity = substr($anycity, $pos1, $sstrt1);
$tncity2 = "";
for ($i = 0, $j = strlen($tncity); $i <= $j; $i++) {
if (substr($tncity, $i, 1) == "_") {
$tncity2 = $tncity2 . " ";
        }
else {
$tncity2 = $tncity2 . substr($tncity, $i, 1);
        }
}

return $tncity2;
}

$time1 = date("g:i A", mktime());
$city1 = "GMT";
$city2 = "Africa/Cairo";

$ncity1 = recity($city1);
$ncity2 = recity($city2);

    $start_time_input = $time1;
    $start_tz = $city1;
    $end_tz = $city2;
    putenv("TZ=$start_tz");
    $start_time = strtotime($start_time_input);
    echo "<p><strong>";
    echo "<BR /><br />";
    echo "<BLOCKQUOTE><FONT SIZE=6>";
    putenv("TZ=$end_tz");
    echo date("l g:i A",$start_time)."\n";
    echo "</strong>";
    echo " in $ncity2.</p>";
    echo "</FONT></BLOCKQUOTE>";
    echo "<BR /><br />";
    echo "<P>return to <A HREF=http://www.easysurf.cc/tmnw4.htm>What Time is it 
now?</A><P>";

?>

------------------------------------------------------------------------
[2013-07-05 07:14:03] a...@php.net

Please post a small PHP code snippet and date related INI directives.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=65201


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65201&edit=1

Reply via email to