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

From: Date: Fri, 29 Oct 2021 14:08:49 +0000
Subject: Bug #81565 [NEW]: BC break: date parsing fails when provided with timezones including seconds
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237427@lists.php.net to get a copy of this message
From:             andrea dot sprega at slope dot it
Operating system: Linux (The only I could try)
PHP version:      8.0.12
Package:          Date/time related
Bug Type:         Bug
Bug description:BC break: date parsing fails when provided with timezones including seconds

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 bug report at https://bugs.php.net/bug.php?id=81565&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81565&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81565&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81565&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81565&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81565&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81565&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81565&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81565&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81565&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81565&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81565&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81565&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81565&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81565&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81565&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81565&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81565&r=mysqlcfg


Thread (12 messages)

« previous php.bugs (#237427) next »