Bug #76374 [Asn->Csd]: Date difference varies according day time

From: Date: Tue, 06 Apr 2021 19:55:34 +0000
Subject: Bug #76374 [Asn->Csd]: Date difference varies according day time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233262@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76374&edit=1 ID: 76374 Updated by: derick@php.net Reported by: fcasadei at fcpartner dot com Summary: Date difference varies according day time -Status: Assigned +Status: Closed Type: Bug Package: Date/time related Operating System: linux & windows PHP Version: 7.0.30 Assigned To: derick Block user comment: N Private report: N New Comment: The fix for this bug has been committed. If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test. Thank you for the report, and for helping us make PHP better. Fixed for PHP 8.1. Previous Comments: ------------------------------------------------------------------------ [2019-02-07 01:19:41] a at b dot c dot de Related To: Bug #77571 ------------------------------------------------------------------------ [2018-05-30 15:15:17] derick@php.net @a - it's not related to DST changeovers (for once). But what happens is that PHP converts it first to UTC time, which ends up comparing 2016-12-31 23:00 to 2017-09-30 22:00 - and then the algorithm gets even more confused and messes up. This code is complex, and needs to be rewritten sadly. It's going to take some time. ------------------------------------------------------------------------ [2018-05-30 13:06:33] fcasadei at fcpartner dot com Geee !! you are the author ?? Congrats Congrats congrats congrats !!! Php is the coolest language I ever used (in 30 yars ... started with 8086 asembly, pascal, cobol, fortran, basic, ... list, ... and some I won't admit) ------------------------------------------------------------------------ [2018-05-30 12:21:27] a at b dot c dot de Given that the interval changed when the time was specified, I did suspect that something happened sometime in the morning the start or the afternoon of the end that changed the length; but No, Europe/Paris doesn't have anything special to say about those dates. I looked at a few other zones and intervals. (a) Asia/Baghdad also displays varying results despite not crossing a DST boundary (b) America/Denver is consistent, even though it does cross a DST boundary. (c) The period from 1 January to 1 February gives consistent results for all zones (d) The period from 1 July to 1 August does not; this time though the affected zones are Europe/Paris, Europe/Lisbon, Asia/Baghdad, and Pacific/Auckland. (e) The number of days is always the same. For the January-October period, it is 273; the variation seen in Europe/Paris and Asia/Baghdad is that 273 days makes nine months when counting from midnight, but only eight months 30 days when counting from midday. <?php $zones_to_try = [ "UTC", "Europe/Paris", "Europe/Lisbon", "Asia/Baghdad", "Pacific/Auckland", "America/Phoenix", "America/Denver", ]; foreach($zones_to_try as $zone) { echo "$zone:\n"; date_default_timezone_set($zone); $objDateTo = new dateTime('2017-10-01'); $objDateFrom = new dateTime('2017-01-01'); $interval = $objDateTo->diff($objDateFrom); echo "From {$objDateFrom->format('c')} to {$objDateTo->format('c')}: {$interval->m}m {$interval->d}d ({$interval->days} days)\n"; $objDateTo = new dateTime('2017-10-01 12:00:00'); $objDateFrom = new dateTime('2017-01-01 12:00:00'); $interval = $objDateTo->diff($objDateFrom); echo "From {$objDateFrom->format('c')} to {$objDateTo->format('c')}: {$interval->m}m {$interval->d}d ({$interval->days} days)\n"; echo "\n\n"; } ?> ------------------------------------------------------------------------ [2018-05-28 17:38:33] derick@php.net Considering that the author is European (me), I can assure you there is nothing US centric here. However, there does seem to be a bug, as it should indeed say 9 in each case. Assigning to myself. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=76374 -- Edit this bug report at https://bugs.php.net/bug.php?id=76374&edit=1

« previous php.bugs (#233262) next »