From: daniel dot rudolf at eifel-online dot com
Operating system: Windows XP
PHP version: 5.3.15
Package: Date/time related
Bug Type: Bug
Bug description:DateTime: "last day of" with timestamps is buggy
Description:
------------
Using new DateTime("last day of @timestamp") doesn't work properly
Test script:
---------------
<?php
$time = new DateTime('2012-01-01 00:00:00 UTC');
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of @'.$time);
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
/* ----------------------------------- */
$time = new DateTime('now'); // today = 2012-08-09
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of @'.$time);
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
/* ----------------------------------- */
$time = new DateTime('2020-12-12');
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of @'.$time);
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
/* ----------------------------------- */
$time = new DateTime('2000-02-01'); // leapyear
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of @'.$time);
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
/* ----------------------------------- */
$time = new DateTime('2000-02-01 00:00:01 UTC');
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of @'.$time);
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
?>
Expected result:
----------------
2012-01-01 --> 2012-01-31
2012-08-09 --> 2012-08-31
2020-12-12 --> 2020-12-31
2000-02-01 --> 2000-02-29
2000-02-01 --> 2000-02-29
Actual result:
--------------
2012-01-01 --> 2012-01-31
2012-08-09 --> 2012-09-08
2020-12-12 --> 2021-01-10
2000-02-01 --> 2000-03-01
2000-02-01 --> 2000-03-02
--
Edit bug report at https://bugs.php.net/bug.php?id=62784&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62784&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62784&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62784&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62784&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62784&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62784&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62784&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62784&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62784&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62784&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62784&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62784&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62784&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62784&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62784&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62784&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62784&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62784&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62784&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62784&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62784&r=mysqlcfg