php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62784 DateTime: "last day of" with timestamps is buggy
Submitted: 2012-08-09 07:58 UTC Modified: -
Votes:4
Avg. Score:3.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: daniel dot rudolf at eifel-online dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.3.15 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel dot rudolf at eifel-online dot com
New email:
PHP Version: OS:

 

 [2012-08-09 07:58 UTC] daniel dot rudolf at eifel-online dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-09 08:04 UTC] daniel dot rudolf at eifel-online dot com
Note that only timestamps are affected!

<?php
$time = new DateTime('2000-02-01 00:00:01 UTC');
$time = $time->getTimestamp();
$monthEnd = new DateTime('last day of '.date('r', $time));
echo date('Y-m-d', $time)." --> ".$monthEnd->format('Y-m-d')."\n";
// Expected and actual result: 2000-02-01 --> 2000-02-29 
?>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Nov 16 11:01:25 2018 UTC