Bug #79452 [Opn]: DateTime::diff() generates months differently between time zones

From: Date: Mon, 06 Apr 2020 11:51:34 +0000
Subject: Bug #79452 [Opn]: DateTime::diff() generates months differently between time zones
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226441@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79452&edit=1 ID: 79452 User updated by: corey dot taylor dot fl at gmail dot com Reported by: corey dot taylor dot fl at gmail dot com Summary: DateTime::diff() generates months differently between time zones Status: Open Type: Bug Package: Date/time related PHP Version: 7.4.4 Block user comment: N Private report: N New Comment: I can see why php calculates the month value different for those UTC DateTime instances. Is there no way to get a consistent calendar operation in different time zones? The only alternative here seems to be mimicking the same "date" in UTC for users in other time zones when calculating calendar changes. Previous Comments: ------------------------------------------------------------------------ [2020-04-06 08:14:06] cmb@php.net Before the actual diff is calculated, the DateTime objects are converted to UTC; doing this in PHP shows the problem[1]. [1] <https://3v4l.org/gBtjX#v720> ------------------------------------------------------------------------ [2020-04-06 01:22:43] corey dot taylor dot fl at gmail dot com Description: ------------ If you create DateTime instances in 'America/New_York' or 'UTC' time zone and compare them using DateTime::diff() the months value is different than using DateTime instances in 'Europe/Berlin' or 'Asia/Tokyo'. date_default_timezone_set('America/New_York'); $from = new DateTime('2019-06-01'); $to = new DateTime('2019-10-01'); var_dump($from->diff($to)->m); -- int(4) date_default_timezone_set('Asia/Tokyo'); $from = new DateTime('2019-06-01'); $to = new DateTime('2019-10-01'); var_dump($from->diff($to)->m); -- int(3) The generated days value is the same for both. If this isn't determined to be an implementation error, then can the exepcation be documented for DateTime::diff()? Right now, it's impossible to tell how the DateTime objects are compared between time zones. Expected result: ---------------- The generated difference in months is the same for 2 dates is the same regardless of the time zone they are in. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79452&edit=1

« previous php.bugs (#226441) next »