Doc #79453 [Opn->Nab]: Modify -1 month works incorrectly at the end of some months
| From: | derick@php.net | Date: | Tue, 07 Apr 2020 08:55:40 +0000 |
| Subject: | Doc #79453 [Opn->Nab]: Modify -1 month works incorrectly at the end of some months | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17462@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79453&edit=1
ID: 79453
Updated by: derick@php.net
Reported by: moras dot pawel at gmail dot com
Summary: Modify -1 month works incorrectly at the end of some
months
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Date/time related
Operating System: Ubuntu 19.04
PHP Version: 7.2.29
Block user comment: N
Private report: N
New Comment:
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
This is already documented at https://www.php.net/manual/en/datetime.examples-arithmetic.php
Previous Comments:
------------------------------------------------------------------------
[2020-04-07 06:03:19] moras dot pawel at gmail dot com
Description:
------------
modify result is not intuitive when going back one month. If the current month has more
days than the last one, modify ('-1 month') can end up in the same month. I believe, if
that is the case, it should fall back to the last day of last month.
The current way this works is completely unintuitive, and at least should be mentioned in the docs.
Test script:
---------------
$date = new DateTime ();
$date->setDate (2020, 03, 30); // 31 days in march
echo $date->format ("Y-m-d h:m:s") . PHP_EOL;
$date->modify ("-1 month"); // only 28 days in february
echo $date->format ("Y-m-d h:m:s") . PHP_EOL;
Expected result:
----------------
2020-03-30 07:03:18
2020-02-28 07:03:18
Actual result:
--------------
2020-03-30 07:03:18
2020-03-01 07:03:18
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79453&edit=1