Bug #80696 [NEW]: Subtracting an interval of 1 month 1 day subtracts one more day

From: Date: Mon, 01 Feb 2021 23:33:10 +0000
Subject: Bug #80696 [NEW]: Subtracting an interval of 1 month 1 day subtracts one more day
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231878@lists.php.net to get a copy of this message
From: jurchiks101 at gmail dot com Operating system: Windows 10 PHP version: 7.4.14 Package: Date/time related Bug Type: Bug Bug description:Subtracting an interval of 1 month 1 day subtracts one more day Description: ------------ When subtracting an interval that contains months and days, the number of days subtracted is sometimes increased by an inconsistent amount. Here's the 3v4l: https://3v4l.org/uIWq4 Test script: --------------- $firstDayOfYear = new DateTimeImmutable('2021-01-01 00:00:00.000000'); for ($i = 1; $i <= 12; $i++) { $intervalOneEach = new DateInterval('P' . $i . 'M1D'); echo $firstDayOfYear ->sub($intervalOneEach) ->diff($firstDayOfYear) ->format('%y years %m months %d days %h hours %i minutes %s seconds'), PHP_EOL; } Expected result: ---------------- 0 years 1 months 1 days 0 hours 0 minutes 0 seconds 0 years 2 months 1 days 0 hours 0 minutes 0 seconds 0 years 3 months 1 days 0 hours 0 minutes 0 seconds 0 years 4 months 1 days 0 hours 0 minutes 0 seconds 0 years 5 months 1 days 0 hours 0 minutes 0 seconds 0 years 6 months 1 days 0 hours 0 minutes 0 seconds 0 years 7 months 1 days 0 hours 0 minutes 0 seconds 0 years 8 months 1 days 0 hours 0 minutes 0 seconds 0 years 9 months 1 days 0 hours 0 minutes 0 seconds 0 years 10 months 1 days 0 hours 0 minutes 0 seconds 0 years 11 months 1 days 0 hours 0 minutes 0 seconds 1 years 0 months 1 days 0 hours 0 minutes 0 seconds Actual result: -------------- 0 years 1 months 2 days 0 hours 0 minutes 0 seconds 0 years 2 months 1 days 0 hours 0 minutes 0 seconds 0 years 3 months 2 days 0 hours 0 minutes 0 seconds 0 years 4 months 1 days 0 hours 0 minutes 0 seconds 0 years 5 months 1 days 0 hours 0 minutes 0 seconds 0 years 6 months 2 days 0 hours 0 minutes 0 seconds 0 years 7 months 1 days 0 hours 0 minutes 0 seconds 0 years 8 months 2 days 0 hours 0 minutes 0 seconds 0 years 9 months 1 days 0 hours 0 minutes 0 seconds 0 years 10 months 3 days 0 hours 0 minutes 0 seconds 0 years 11 months 1 days 0 hours 0 minutes 0 seconds 1 years 0 months 1 days 0 hours 0 minutes 0 seconds -- Edit bug report at https://bugs.php.net/bug.php?id=80696&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80696&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80696&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80696&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80696&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80696&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80696&r=support Expected behavior: https://bugs.php.net/fix.php?id=80696&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80696&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80696&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80696&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80696&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80696&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80696&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80696&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80696&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80696&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80696&r=mysqlcfg

« previous php.bugs (#231878) next »