Bug #66294 [NEW]: Timezone display and Timestamps are incorrect when using GMT+/- timezones
| From: | jrossiter at dlvr dot it | Date: | Sat, 14 Dec 2013 07:18:29 +0000 |
| Subject: | Bug #66294 [NEW]: Timezone display and Timestamps are incorrect when using GMT+/- timezones | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183329@lists.php.net to get a copy of this message | ||
From: jrossiter at dlvr dot it
Operating system: Ubuntu 13.04
PHP version: 5.5.7
Package: Date/time related
Bug Type: Bug
Bug description:Timezone display and Timestamps are incorrect when using GMT+/- timezones
Description:
------------
Creating a new DateTime object using a fixed string with a "GMT(+/-)nn"
timezone (e.g. "GMT+12" or "GMT-10") results in the correct date and
time being displayed, with but a badly formatted timezone ("GMT+1200",
"GMT-1000")
(A note if the reader isn't aware... the Etc/GMT timezones actually
perform the opposite of what they appear to be requesting. GMT+12 is
actually GMT minus 12 hours, and GMT-10 is actually GMT plus 10 hours)
The unix timestamp returned by this object is incorrect by 2*offset.
So, the GMT+12 returns a timestamp decremented 24 hours. The GMT-10
returns a date/time incremented by 20 hours.
Creating a new DateTime object and passing in a DateTimeZone object
using an Etc/GMT(+/-)nn (e.g. "Etc/GMT+12") timezone displays
timestamps and formatted timezone as expected.
Test script:
---------------
foreach (['Etc/GMT+12', 'Etc/GMT-10'] as $timezone) {
$dTZ = new DateTimeZone($timezone);
// Create a DateTime using the DateTimeZone object
// This will display both formatted and unix timestamp as expected
$dT = new DateTime('2013-12-13 18:49:00', $dTZ);
echo $dT->format('Y-m-d H:i:s T'), PHP_EOL;
echo $dT->getTimestamp(), PHP_EOL;
// Create a DateTime using only a string representation
// This will display the formatted date/time as expected,
// but with the incorrect timezone
// The value returned by getTimestamp() for format('U') will
// be off by 2*offset
$dT2 = new DateTime($dT->format('Y-m-d H:i:s T'));
echo $dT2->format('Y-m-d H:i:s T'), PHP_EOL;
echo $dT2->getTimestamp(), PHP_EOL, PHP_EOL;
}
Expected result:
----------------
2013-12-13 18:49:00 GMT+12
1387003740
2013-12-13 18:49:00 GMT+12
1387003740
2013-12-13 18:49:00 GMT-10
1386924540
2013-12-13 18:49:00 GMT-10
1386924540
Actual result:
--------------
2013-12-13 18:49:00 GMT+12
1387003740
2013-12-13 18:49:00 GMT+1200
1386917340
2013-12-13 18:49:00 GMT-10
1386924540
2013-12-13 18:49:00 GMT-1000
1386996540
--
Edit bug report at https://bugs.php.net/bug.php?id=66294&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66294&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66294&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66294&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66294&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66294&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66294&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66294&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66294&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66294&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66294&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66294&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66294&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66294&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66294&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66294&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66294&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66294&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66294&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66294&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66294&r=mysqlcfg