From: christopher dot jf dot hopper at gmail dot com Operating system: Linux 2.6.32-220.17.1.el6.i686 PHP version: 5.3.17 Package: Date/time related Bug Type: Bug Bug description:DateTime::createFromFormat() with a Unix timestamp can be one day off
Description: ------------ == PHP Version Information == # php --version PHP 5.3.3 (cli) (built: May 7 2012 19:58:17) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans # cat /proc/version Linux version 2.6.32-220.17.1.el6.i686 (mockbu...@c6b5.bsys.dev.centos.org) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue May 15 22:09:39 BST 2012 == Describing The Problem == When using the static method DateTime::createFromFormat() or the new DateTime() constructor to create a DateTime object instance from a Unix Timestamp, the resulting date can be one day out, even though the timestamp is not. To reproduce the bug, run the test script below. Test script: --------------- <?php // Bad $d=DateTime::createFromFormat("!Y-m-d H:i:s", "2012-11-30 00:00:00"); echo $d->getTimestamp() . PHP_EOL; echo $d->format("Y-m-d") . PHP_EOL; $e=new DateTime("@". $d->getTimestamp()); echo $e->getTimestamp() . PHP_EOL; echo $e->format("Y-m-d") . PHP_EOL . PHP_EOL; /* 1354194000 2012-11-30 1354194000 2012-11-29 */ // Bad $d=DateTime::createFromFormat("!Y-m-d H:i:s", "2012-11-30 00:00:00"); echo $d->getTimestamp() . PHP_EOL; echo $d->format("Y-m-d") . PHP_EOL; $e=DateTime::createFromFormat("U", $d->getTimestamp()); echo $e->getTimestamp() . PHP_EOL; echo $e->format("Y-m-d") . PHP_EOL . PHP_EOL; /* 1354194000 2012-11-30 1354194000 2012-11-29 */ // Good $d=DateTime::createFromFormat("!Y-m-d H:i:s", "2012-11-30 00:00:00"); echo $d->getTimestamp() . PHP_EOL; echo $d->format("Y-m-d") . PHP_EOL; $e=new DateTime(); $e->setTimestamp($d->getTimestamp()); echo $e->getTimestamp() . PHP_EOL; echo $e->format("Y-m-d") . PHP_EOL; /* 1354194000 2012-11-30 1354194000 2012-11-30 */ Expected result: ---------------- 1354194000 2012-11-30 1354194000 2012-11-30 1354194000 2012-11-30 1354194000 2012-11-30 1354194000 2012-11-30 1354194000 2012-11-30 Actual result: -------------- 1354194000 2012-11-30 1354194000 2012-11-29 1354194000 2012-11-30 1354194000 2012-11-29 1354194000 2012-11-30 1354194000 2012-11-30 -- Edit bug report at https://bugs.php.net/bug.php?id=63234&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63234&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63234&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63234&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63234&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63234&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63234&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63234&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63234&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63234&r=support Expected behavior: https://bugs.php.net/fix.php?id=63234&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63234&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63234&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63234&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63234&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63234&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63234&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63234&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63234&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63234&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63234&r=mysqlcfg