Bug #80610 [Opn]: DateTime calculate wrong with DateInterval

From: Date: Sat, 09 Jan 2021 23:23:21 +0000
Subject: Bug #80610 [Opn]: DateTime calculate wrong with DateInterval
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231472@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80610&edit=1 ID: 80610 User updated by: info at mobger dot de Reported by: info at mobger dot de Summary: DateTime calculate wrong with DateInterval Status: Open Type: Bug Package: *Calendar problems Operating System: Docker / PHPSandbox? PHP Version: 7.4.14 Block user comment: N Private report: N New Comment: It seems not to be a bug. I ignored the problem of summertime, which is not really good described in the documentation. $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20761M'); $expectEaster->sub($interval); echo('recalc '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n" ); $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20760M'); $expectEaster->sub($interval); echo('recalc '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20701M'); $expectEaster->sub($interval); echo('recalc '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20700M'); $expectEaster->sub($interval); echo('recalc '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n"); // recalc 2020-03-29 00:59:00 // remove the missing hour // easter 2020-04-12 11:00:00 // remove the missing hour a second time via adding // recalc 2020-03-29 03:00:00 // easter 2020-04-12 13:00:00 // recalc 2020-03-29 03:59:00 // easter 2020-04-12 13:00:00 // recalc 2020-03-29 03:00:00 // easter 2020-04-12 12:00:00 Previous Comments: ------------------------------------------------------------------------ [2021-01-09 21:42:45] info at mobger dot de Description: ------------ I want to add and sub some minutes fram a date. I use the dateInterval for the calculation. It seems to work with lower numbers of minutes. I have not tested it systemattically. If I üpersonally use PHP 7.4 in my local development (ddev/docker). But I Can repoduce the bug online https://sandbox.onlinephpfunctions.com/ with various php-versions. 8.0.0, 7.4.13, 7.3.25, 7.2.31, 7.1.33, 7.0.14 and 5.6.29. Test script: --------------- <?php //Enter your code here, enjoy! $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20800M'); $expectEaster->sub($interval); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n" ); $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20715M'); $expectEaster->sub($interval); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n"); $expectEaster = date_create_from_format('Y-m-d H:i:s', '2020-04-12 12:00:00', new DateTimeZone('Europe/Berlin')); $interval = new DateInterval('PT20700M'); $expectEaster->sub($interval); $expectEaster->add($interval); echo('easter '.$expectEaster->format('Y-m-d H:i:s')."\n"); // Result // easter 2020-04-12 11:00:00 // easter 2020-04-12 13:00:00 // easter 2020-04-12 12:00:00 Expected result: ---------------- easter 2020-04-12 12:00:00 Actual result: -------------- 'PT20800M': easter 2020-04-12 11:00:00 'PT20715M': easter 2020-04-12 13:00:00 'PT20700M': easter 2020-04-12 12:00:00 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80610&edit=1

« previous php.bugs (#231472) next »