Bug #81565 [Com]: BC break: date parsing fails when provided with timezones including seconds

From: Date: Tue, 02 Nov 2021 13:29:37 +0000
Subject: Bug #81565 [Com]: BC break: date parsing fails when provided with timezones including seconds
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237508@lists.php.net to get a copy of this message
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: https://www.php.net/manual/en/datetime.createfromformat.php where the timezone format is described. Previous Comments: ------------------------------------------------------------------------ [2021-11-02 13:28:15] ximarx at gmail dot com According to https://www.iana.org/time-zones tzdata, basically ~any timezone for an "old enough" date in the past is assigned to a sub-minute offset value E.g.: ``` America/Los_Angeles Initially: -07:52:58 standard LMT 1883-11-18 20:00:00Z -08:00:00 standard PST ``` ``` America/Los_Angeles Initially: -07:52:58 standard LMT 1883-11-18 20:00:00Z -08:00:00 standard PST ``` ``` Europe/London Initially: -00:01:15 standard LMT 1847-12-01 00:01:15Z +00:00:00 standard GMT ``` As reference: GNU date (coreutils) using tzdata 2021e ``` $ dpkg -s tzdata | grep -i version Version: 2021e-0ubuntu0.20.04 $ TZ="Europe/Rome" date -d"Sat, 28 Jul 1838 17:12:33 +0000" +"%F %T %:::z" 1838-07-28 18:02:29 +00:49:56 $ TZ="Europe/London" date -d"Sat, 28 Jul 1838 17:12:33 +0000" +"%F %T %:::z" 1838-07-28 17:11:18 -00:01:15 ``` ------------------------------------------------------------------------ [2021-11-02 12:37:43] heiglandreas@php.net @alec > According to the documentation +00:49:56 is not a correct timezone. Do you have a link to that documentation? ------------------------------------------------------------------------ [2021-11-02 11:54:37] alec at alec dot pl 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. ------------------------------------------------------------------------ [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=78984 https://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

« previous php.bugs (#237508) next »