php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77788 date_add returns invalid time during DST transition
Submitted: 2019-03-24 09:31 UTC Modified: 2021-04-18 04:22 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: r dot schuil at gmail dot com Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 7.2.16 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: r dot schuil at gmail dot com
New email:
PHP Version: OS:

 

 [2019-03-24 09:31 UTC] r dot schuil at gmail dot com
Description:
------------
When the addition to date/time causes it to be within the hour of DST transition, PHP returns an invalid date/time.
For example, 2019-01-31 02:00:12 plus two months returns 2019-03-31 02:00:12, which gets rejected by MySQL because the 3rd hour does not exist on this date. Instead, it should return 2019-03-31 03:00:12

Test script:
---------------
<?php
$date = date_create('2019-01-31 02:00:12');
date_add($date, date_interval_create_from_date_string('2 months'));
echo date_format($date, 'Y-m-d H:i:s');
?>


Expected result:
----------------
2019-03-31 03:00:12


Actual result:
--------------
2019-03-31 02:00:12


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-24 09:37 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2019-03-24 09:37 UTC] requinix@php.net
What does date_default_timezone_get() return?
 [2019-03-24 09:43 UTC] r dot schuil at gmail dot com
-Status: Feedback +Status: Open
 [2019-03-24 09:43 UTC] r dot schuil at gmail dot com
$ php -r 'echo date_default_timezone_get();
Europe/Berlin
 [2020-01-20 17:22 UTC] girgias@php.net
-Assigned To: +Assigned To: derick
 [2021-03-28 07:34 UTC] r dot schuil at gmail dot com
Still not fixed?
 [2021-04-06 19:02 UTC] derick@php.net
-Status: Assigned +Status: Feedback
 [2021-04-06 19:02 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

I can't reproduce this with PHP 7.2.10, 7.2.35, 7.3.25, nor 8.0.3: 

8.0.4-dev derick@gargleblaster:~/dev/php/php-src.git$ php -ddate.timezone=Europe/Berlin
<?php
$date = date_create('2019-01-31 02:00:12');
date_add($date, date_interval_create_from_date_string('2 months'));
echo date_format($date, 'Y-m-d H:i:s');
?>


2019-03-31 03:00:12
 [2021-04-18 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2022-03-28 07:34 UTC] george dot chailazopoulos at gmail dot com
This issue is not fixed.
Derick your should test the script with php -ddate.timezone=Europe/Athens instead of Berlin
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC