|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65201 Africa/Cairo time off by 1 hour
Submitted: 2013-07-04 00:32 UTC Modified: 2014-02-08 20:46 UTC
Avg. Score:4.0 ± 1.0
Reproduced:0 of 0 (0.0%)
From: easysurf at easysurf dot cc Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.5.0 OS: Window 8
Private report: No CVE-ID: None
 [2013-07-04 00:32 UTC] easysurf at easysurf dot cc
Africa/Cairo timezone is off by one hour.

Expected result:
If it is 10:00 am in Cairo it should not say 11:00


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-04 06:39 UTC]
-Status: Open +Status: Feedback
 [2013-07-04 06:39 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Please post also all the datetime related ini options you have.
 [2013-07-05 00:23 UTC] easysurf at easysurf dot cc
-Status: Feedback +Status: Open
 [2013-07-05 00:23 UTC] easysurf at easysurf dot cc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE>What Time is it Now - Select a Location</TITLE>
<BODY BGCOLOR="#FFFAF0" TEXT=#000000 LINK="Blue" VLINK="#0000A0" ALINK="Blue" >
<form action="" method="post">
<TR><TH>Select a Location</TH></TR>
<select class=debu3 name="city2">
<option value="Africa/Cairo">Cairo</option>
<input type="submit" name="submit" value="Click to Calculate" />

 [2013-07-05 07:14 UTC]
-Status: Open +Status: Feedback
 [2013-07-05 07:14 UTC]
Please post a small PHP code snippet and date related INI directives.
 [2013-07-06 02:08 UTC] easysurf at easysurf dot cc
-Status: Feedback +Status: Open
 [2013-07-06 02:08 UTC] easysurf at easysurf dot cc

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;
    $start_time = strtotime($start_time_input);
    echo "<p><strong>";
    echo "<BR /><br />";
    echo "<BLOCKQUOTE><FONT SIZE=6>";
    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=>What Time is it now?</A><P>";

 [2013-07-06 09:17 UTC]
-Status: Open +Status: Feedback
 [2013-07-06 09:17 UTC]
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

echo date('l g:i A');

Do that two lines work for you?
 [2013-07-06 21:27 UTC] easysurf at easysurf dot cc
-Status: Feedback +Status: Open
 [2013-07-06 21:27 UTC] easysurf at easysurf dot cc
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.


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-07 08:17 UTC]
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-19 18:59 UTC] mail+php at requinix dot net
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

echo date("l g:i A")."\n";

All that aside, 5.3 is now EOL and 5.4+ doesn't use TZ.
 [2014-02-08 20:46 UTC]
-Status: Open +Status: Not a bug
 [2014-02-08 20:46 UTC]
Thanks for research, mail+php at requinix dot net :)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 20:01:32 2024 UTC