Edit report at https://bugs.php.net/bug.php?id=81565&edit=1
ID: 81565
Comment by: alec at alec dot pl
Reported by: andrea dot sprega at slope dot it
Summary: BC break: date parsing fails when provided with
timezones including seconds
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux (The only I could try)
PHP Version: 8.0.12
Block user comment: N
Private report: N
New Comment:
According to the documentation +00:49:56 is not a correct timezone. So, the behavior sounds right no
me.
DateTime::getLastErrors() in this case contains "The timezone could not be found in the
database" error.
Previous Comments:
------------------------------------------------------------------------
[2021-10-29 15:13:35] cmb@php.net
For reference: <https://3v4l.org/BeEcm>.
------------------------------------------------------------------------
[2021-10-29 14:08:49] andrea dot sprega at slope dot it
Description:
------------
Past dates in some timezones used to have "weird" timezones that included seconds. Example
for Europe/Rome: https://nodatime.org/tzvalidate/generate?version=2019a&zone=Europe/Rome
Starting from PHP 8.0.10, parsing for dates with timezones including seconds started to fail --
DateTime::createFromFormat started returning false instead of a DateTime, even if it previously
ignored the fractional timezone (which is fine, assuming seconds are not supported by PHP
timezones).
This is a BC break for all applications that work with this kind of dates.
We believe this could be a side effect of one of these issues:
https://bugs.php.net/bug.php?id=78984https://bugs.php.net/bug.php?id=79580
NOTE: we found out about this because of an incorrect, non validated input of a user that wrote
"21" instead of "2021" as year, thus producing this weird date that ended up in
our database. Then, when reading back that date on a connection with timezone set to Europe/Rome,
the database performs the conversion and correctly adds the fractional timezone valid for year 21
AD.
We currently worked around the issue by manually removing seconds from the timezone (which basically
restored the behavior up to 8.0.9).
Test script:
---------------
<?php
var_export(
\DateTime::createFromFormat(
'Y-m-d H:i:sO',
'0021-08-21 00:00:00+00:49:56'
)
);
// NOTE: any date before 1893-10-31 23:00:00Z (with fractional timezone, as you can see from the
link in the description) would reproduce the issue
Expected result:
----------------
DateTime::__set_state(array(
'date' => '0021-08-21 00:00:56.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
))
Actual result:
--------------
false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81565&edit=1