Bug #79453 [NEW]: Modify -1 month works incorrectly at the end of some months

From: Date: Tue, 07 Apr 2020 06:03:19 +0000
Subject: Bug #79453 [NEW]: Modify -1 month works incorrectly at the end of some months
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226445@lists.php.net to get a copy of this message
From: moras dot pawel at gmail dot com Operating system: Ubuntu 19.04 PHP version: 7.2.29 Package: Date/time related Bug Type: Bug Bug description:Modify -1 month works incorrectly at the end of some months 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 bug report at https://bugs.php.net/bug.php?id=79453&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79453&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79453&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79453&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79453&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79453&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79453&r=support Expected behavior: https://bugs.php.net/fix.php?id=79453&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79453&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79453&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79453&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79453&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79453&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79453&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79453&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79453&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79453&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79453&r=mysqlcfg

« previous php.bugs (#226445) next »