Bug #62784 [Opn->Csd]: DateTime: "last day of" with timestamps is buggy
| From: | derick@php.net | Date: | Fri, 13 May 2022 13:41:28 +0000 |
| Subject: | Bug #62784 [Opn->Csd]: DateTime: "last day of" with timestamps is buggy | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241493@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62784&edit=1
ID: 62784
Updated by: derick@php.net
Reported by: daniel dot rudolf at eifel-online dot com
Summary: DateTime: "last day of" with timestamps is buggy
-Status: Open
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: Windows XP
PHP Version: 5.3.15
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2022-05-13 13:41:16] derick@php.net
The phrase "last day of @7289347234" really does not have any meaning, so I am not sure
whether it makes sense to do anything here. I am closing this, as this would increase the parser
complexity significantly, with a reasonable workaround available. If you have a really compelling
case, feel free to add a ticket to https://github.com/php/php-src/issues, but it
needs to have a really good reason for this to get added.
------------------------------------------------------------------------
[2012-08-09 08:04:58] 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
?>
------------------------------------------------------------------------
[2012-08-09 07:58:46] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62784&edit=1