Bug #77220 [Opn->Nab]: Problem for month March (DateTime::sub)
| From: | cmb@php.net | Date: | Thu, 29 Nov 2018 16:35:49 +0000 |
| Subject: | Bug #77220 [Opn->Nab]: Problem for month March (DateTime::sub) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218213@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77220&edit=1
ID: 77220
Updated by: cmb@php.net
Reported by: info at 4md dot eu
Summary: Problem for month March (DateTime::sub)
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Any
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
.
Previous Comments:
------------------------------------------------------------------------
[2018-11-29 16:35:15] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
See <http://php.net/manual/en/datetime.sub.php#refsect1-datetime.sub-examples>,
example 3.
------------------------------------------------------------------------
[2018-11-29 15:11:03] info at 4md dot eu
Description:
------------
If substract 1 Month for 31/30/29 march => Not correctly subtract (possible problem to February
Month).
Test script:
---------------
<?php
$intervalMonth = new DateInterval('P1M');
$dates = ['2019-01-30', '2019-02-28', '2019-03-29',
'2019-03-30', '2019-03-31', '2019-04-30'];
foreach($dates as $date){
$d = new DateTime($date);
// Substract 1 Month
$d->sub($intervalMonth);
$subMonth = $d->format('Y-m-d');
// Adding 1 Month
$d->add($intervalMonth);
$addMonth = $d->format('Y-m-d');
// Echo information
if(substr($date, 0, 7) === '2019-03'){
echo '*';
}
echo 'Now: '.$date.'; Sub 1Month: '.$subMonth."; Add Month:
".$addMonth."\n";
}
echo "\n";
echo '* BUG';
Actual result:
--------------
Now: 2019-01-30; Sub 1Month: 2018-12-30; Add Month: 2019-01-30
Now: 2019-02-28; Sub 1Month: 2019-01-28; Add Month: 2019-02-28
*Now: 2019-03-29; Sub 1Month: 2019-03-01; Add Month: 2019-04-01
*Now: 2019-03-30; Sub 1Month: 2019-03-02; Add Month: 2019-04-02
*Now: 2019-03-31; Sub 1Month: 2019-03-03; Add Month: 2019-04-03
Now: 2019-04-30; Sub 1Month: 2019-03-30; Add Month: 2019-04-30
* BUG
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77220&edit=1