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

From: Date: Fri, 29 Oct 2021 15:13:35 +0000
Subject: Bug #81565 [Opn]: 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-237428@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
 Updated by:         cmb@php.net
 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:

For reference: <https://3v4l.org/BeEcm>.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (12 messages)

« previous php.bugs (#237428) next »