Bug #76374 [Com]: Date difference varies according day time

From: Date: Wed, 30 May 2018 12:21:30 +0000
Subject: Bug #76374 [Com]: Date difference varies according day time
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215435@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 Comment by: a at b dot c dot de Reported by: fcasadei at fcpartner dot com Summary: Date difference varies according day time Status: Assigned 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: 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"; } ?> Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2018-05-28 13:41:31] fcasadei at fcpartner dot com thanks but with ("date.timezone", "Europe/Paris"), back to 8 and 9 !! Is PHP another american centric stuff ? ini_set("date.timezone", "Europe/Paris"); $objDateTo = new dateTime('2017-10-01'); $objDateFrom = new dateTime('2017-01-01'); $interval = $objDateTo->diff($objDateFrom); echo $interval->m; $objDateTo = new dateTime('2017-10-01 00:00:00'); $objDateFrom = new dateTime('2017-01-01 00:00:00'); $interval = $objDateTo->diff($objDateFrom); echo $interval->m; $objDateTo = new dateTime('2017-10-01 12:00:00'); $objDateFrom = new dateTime('2017-01-01 12:00:00'); $interval = $objDateTo->diff($objDateFrom); echo $interval->m; gives 889 !! 12 hours make a month ??? ------------------------------------------------------------------------ [2018-05-26 14:15:00] rauljosesantos at gmail dot com If you define your timezone: ini_set("date.timezone", "GMT"); Both work nicely https://3v4l.org/SuVe2 ini_set("date.timezone", "GMT"); $objDateTo = new dateTime('2017-10-01') $objDateFrom = new dateTime('2017-01-01 $interval = $objDateTo->diff($objDateFr echo "Date Only: " . $interval->m . "\r $objDateTo = new dateTime('2017-10-01 1 $objDateFrom = new dateTime('2017-01-01 $interval = $objDateTo->diff($objDateFr echo "Date and Time: " . $interval->m; ------------------------------------------------------------------------ [2018-05-26 13:18:19] fcasadei at fcpartner dot com In France, I don't know exactly. ------------------------------------------------------------------------ [2018-05-26 12:35:52] a at b dot c dot de I get 8 in both cases (more precisely, 8 months, 30 days - just shy of nine months). When exactly does Daylight Saving start in your locale? ------------------------------------------------------------------------ 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 (#215435) next »