php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80896 Daylight time mishandled for America/Havana and Asia/Tehran timezones
Submitted: 2021-03-22 19:01 UTC Modified: 2021-03-22 20:27 UTC
From: ctiancheng at fb dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 8.0Git-2021-03-22 (Git) OS:
Private report: No CVE-ID: None
 [2021-03-22 19:01 UTC] ctiancheng at fb dot com
Description:
------------
---
From manual page: https://php.net/timezones.america
---
America/Havana and Asia/Tehran are two supported timezones listed from the documentation. However, The DateTime are not handled correctly during daylight time transition.
This happens when doing $dt->add(new DateInterval('P1D'));

On e.g. 2021/03/14 for America/Havana
On e.g. 2021/03/21 for Asia/Tehran


Test script:
---------------
// http://sandbox.onlinephpfunctions.com/code/0650352a9684872c8dcfff00a64b11660a56eba8
$local_timezone_name = 'America/Havana';
$timestamp = 1615611600; // local time 3/13/21 0:00
$time = (new DateTime())->setTimestamp($timestamp)
      ->setTimezone(new DateTimeZone($local_timezone_name));
$time->add(new DateInterval('P1D')); // local time 03/13/21 1:00

// http://sandbox.onlinephpfunctions.com/code/623d5587f5453dd487492e5fde64cc836a84dcd9
$local_timezone_name = 'Asia/Tehran';
$timestamp = 1616272200; // local time 3/21/21 0:00
$time = (new DateTime())->setTimestamp($timestamp)
      ->setTimezone(new DateTimeZone($local_timezone_name));
$time->add(new DateInterval('P1D')); // local time 03/22/21 1:00



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-22 19:18 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: *General Issues +Package: Date/time related
 [2021-03-22 19:18 UTC] requinix@php.net
Looks right to me. https://3v4l.org/7sCi5
 [2021-03-22 19:30 UTC] ctiancheng at fb dot com
I find the behavior to be inconsistent with other timezones.
For example in https://3v4l.org/KAl19, with America/Los_Angeles, 3/13/21 0:00 -> 3/14/21 0:00, with daylight time change happening on 3/14. 
I think we assume ->add(new DateInterval("P1D")) would do 0:00am => 0:00am of next day, rather than just adding 24 hours?
 [2021-03-22 19:39 UTC] requinix@php.net
-Status: Feedback +Status: Not a bug
 [2021-03-22 19:39 UTC] requinix@php.net
> I find the behavior to be inconsistent with other timezones.

Tell that to the people who decide at what time their region's clocks should advance.

Cuba and Tehran do it at midnight. Most of the US does it at 2am. Other places in the world advance at 1am.
https://en.wikipedia.org/wiki/Daylight_saving_time_by_country

Dates are hard.
 [2021-03-22 19:57 UTC] derick@php.net
FWIW, zdump -v America/Havana -c 2021,2022 gives:

America/Havana  Sun Mar 14 04:59:59 2021 UT = Sat Mar 13 23:59:59 2021 CST isdst=0 gmtoff=-18000
America/Havana  Sun Mar 14 05:00:00 2021 UT = Sun Mar 14 01:00:00 2021 CDT isdst=1 gmtoff=-14400


Which indicates that "Sun Mar 14 00:00:00" does not exist. Sat Mar 13 23:59:59 is followed by Sun Mar 14 01:00:00.

Tehran has the same issue a week later:

Asia/Tehran  Sun Mar 21 20:29:59 2021 UT = Sun Mar 21 23:59:59 2021 +0330 isdst=0 gmtoff=12600
Asia/Tehran  Sun Mar 21 20:30:00 2021 UT = Mon Mar 22 01:00:00 2021 +0430 isdst=1 gmtoff=16200


Los Angeles exhibits the same problem for "02:00 am":

$ php -ddate.timezone=America/Los_Angeles -r 'echo (new DateTime("2021-03-13 02:00"))->add(new DateInterval("P1D"))->format( DateTime::ISO8601 );'
2021-03-14T03:00:00-0700
 [2021-03-22 20:27 UTC] ctiancheng at fb dot com
Thanks! That resolves my questions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 07:01:28 2024 UTC