php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81562 DateTime returns incorrect time on a very specific date (1895-01-01)
Submitted: 2021-10-28 18:32 UTC Modified: 2022-05-13 15:43 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: abrlam at yahoo dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Ubuntu 18.04.4 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: abrlam at yahoo dot com
New email:
PHP Version: OS:

 

 [2021-10-28 18:32 UTC] abrlam at yahoo dot com
Description:
------------
When time zone is set as America/Toronto, DateTime returns incorrect time on a very specific date (1895-01-01).

This happens in PHP version 7.4.20 and possibly in earlier versions (>=7.3.5).

Test script:
---------------
//fails in 1895-01-01
for($i = 1890; $i <= 1910 ; $i++) {
	$date = new DateTime( $i. '-01-01', new DateTimeZone('America/Toronto'));
	echo $date->format('Y-m-d H:i:s') . "<br />";
}

Expected result:
----------------
For 1895-01-01, it should be 1895-01-01 00:00:00 instead of 1895-01-01 00:17:32.

Actual result:
--------------
1890-01-01 00:00:00
1891-01-01 00:00:00
1892-01-01 00:00:00
1893-01-01 00:00:00
1894-01-01 00:00:00
1895-01-01 00:17:32 <========== Expected value: 1895-01-01 00:00:00
1896-01-01 00:00:00
1897-01-01 00:00:00
1898-01-01 00:00:00
1899-01-01 00:00:00
1900-01-01 00:00:00
1901-01-01 00:00:00
1902-01-01 00:00:00
1903-01-01 00:00:00
1904-01-01 00:00:00
1905-01-01 00:00:00
1906-01-01 00:00:00
1907-01-01 00:00:00
1908-01-01 00:00:00
1909-01-01 00:00:00
1910-01-01 00:00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-29 11:29 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-10-29 11:29 UTC] cmb@php.net
Confirmed: <https://3v4l.org/NLAnOY>.

This is apparently caused by the uncommon timezone transition on
that particular date[1], where the minutes and seconds are not
properly handled.

[1] <https://3v4l.org/VEUib>
 [2022-05-13 15:43 UTC] derick@php.net
-Status: Verified +Status: Not a bug
 [2022-05-13 15:43 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This turned out to be correct. Look at the transitions:

derick@gargleblaster:~$ zdump -v America/Toronto -c 0,1900

America/Toronto  Tue Jan  1 05:17:31 1895 UT = Mon Dec 31 23:59:59 1894 LMT isdst=0 gmtoff=-19052
America/Toronto  Tue Jan  1 05:17:32 1895 UT = Tue Jan  1 00:17:32 1895 EST isdst=0 gmtoff=-18000

The date/time "1895-01-01 00:00:00 America/Toronto" does not exist, as at that exact point the area changed timezones to advance by 17m32s (1052s difference in UTC offset). 

PHP and timelib handle this correctly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 08:01:29 2024 UTC