|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-10-29 14:08 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 18:00:01 2025 UTC |
$date = \DateTime::createFromFormat( 'Y-m-d H:i:sO', '0021-08-21 00:00:00+00:49:56' ); var_dump($date); //timezone UTC or +00:00?. Error Real timezone is +2996 From php 8.0.10 DateTimeZone relative to fix bug #81097 (maybe this BC). DateTime takes no seconds but uses the type +hh:mm for the time zone bug #70701