Bug #77220 [NEW]: Problem for month March (DateTime::sub)

From: Date: Thu, 29 Nov 2018 15:11:03 +0000
Subject: Bug #77220 [NEW]: Problem for month March (DateTime::sub)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218211@lists.php.net to get a copy of this message
From: info at 4md dot eu Operating system: Any PHP version: Irrelevant Package: Date/time related Bug Type: Bug Bug description:Problem for month March (DateTime::sub) 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 bug report at https://bugs.php.net/bug.php?id=77220&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77220&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77220&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77220&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77220&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77220&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77220&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77220&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77220&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77220&r=support Expected behavior: https://bugs.php.net/fix.php?id=77220&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77220&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77220&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77220&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77220&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77220&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77220&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77220&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77220&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77220&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77220&r=mysqlcfg

« previous php.bugs (#218211) next »