Home » Date and Time » Date » Bug #2697
Date does not return UTC
Details
| Submitted | 2004-11-05 02:34 UTC |
|---|---|
| From | paul at serby dot net |
| Assigned | pajoye |
| Status | Closed |
| Package | Date |
| PHP Version | 4.3.9 |
| OS | Debian Linux 2.6.8 |
| Roadmaps | (Not assigned) |
Comments
[2004-11-05 02:34 UTC] paul at serby dot net
Description:
------------
On a system where the System Clock is set to UTC and the
locale it set to Great Britain during the DST of BST the
Date object returns BST(GMT+1) but says it UTC.
The same happens with all locale's with DST
This bug is fixed if you add all the DSTs to the TimeZone
Data array (_DATE_TIMEZONE_DATA).
ie
'BST' => array(
'offset' => 3600000,
'longname' => "British Summer Time",
'shortname' => 'BST',
'hasdst' => false ),
Reproduce code:
---------------
<pre>
<?php
// Safe Mode must be disabled
// System time as UTC
echo "System UTC:\n" . `/bin/date -u +'%d %b %Y %R:%S %Z'` . "\n";
echo $_DATE_TIMEZONE_DEFAULT;
// System time as default locale (GB)
echo "System Default Locale:\n" . `/bin/date +'%d %b %Y %R:%S %Z'` . "\n";
// PHP - Current time UTC
echo "PHP UTC:\n" . gmdate("d M Y H:i:s T",time()) . "\n\n";
// PHP - Current time default locale
echo "PHP Default Locale\n" . date("d M Y H:i:s T",time()) . "\n\n";
require_once("Date.php");
$date = new Date();
// Date Class - Default TimeZone BST
echo "Date Class BST:\n" . $date->format("%d %b %Y %R:%S %Z") . "\n\n";
// Current TimeZone Should be BST (GMT+1)
echo "Timezone: " . $date->tz->longname . "\n\n";
$date->convertTZbyID("UTC");
echo "Date Class UTC:\n" . $date->format("%d %b %Y %R:%S %Z") . "\n\n";
?>
</pre>
Expected result:
----------------
System UTC:
05 Oct 2004 00:35:17 UTC
System Default Locale:
05 Oct 2004 01:35:17 BST
PHP UTC:
05 Oct 2004 00:35:17 GMT
PHP Default Locale
05 Oct 2004 01:35:17 BST
Date Class BST:
05 Oct 2004 01:35:17 BST
Timezone: British Summer Time
Date Class UTC:
05 Oct 2004 00:35:17 UTC
Actual result:
--------------
System UTC:
05 Oct 2004 00:35:17 UTC
System Default Locale:
05 Oct 2004 01:35:17 BST
PHP UTC:
05 Oct 2004 00:35:17 GMT
PHP Default Locale
05 Oct 2004 01:35:17 BST
Date Class BST:
05 Oct 2004 01:35:17 UTC
Timezone: Coordinated Universal Time
Date Class UTC:
05 Oct 2004 01:35:17 UTC
[2006-01-29 07:58 UTC] play at noiseusse dot org
I was having a similar probem. date objects were returning local times when set to utc. I tracked it down to Date_TimeZone::inDaylightTime().
It was
putenv("TZ=".$env_tz);
I changed to:
if ($env_tz != "") {
putenv("TZ=".$env_tz);
}
Not exactly sure what the larger implications are or if it's system dependent but it seemed to work for me.