Bug #79717 [NEW]: Inconsistent handling of 5-digit years

From: Date: Fri, 19 Jun 2020 16:49:32 +0000
Subject: Bug #79717 [NEW]: Inconsistent handling of 5-digit years
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227560@lists.php.net to get a copy of this message
From: a dot schilder at gmx dot de Operating system: PHP version: 7.4.7 Package: Date/time related Bug Type: Bug Bug description:Inconsistent handling of 5-digit years Description: ------------ When adding intervals to a date time, this can result in a 5-digit year. When formating this date time, the format "Y" (which should output a 4 digit year following the documentation) outputs a 5-digit year - but it's not possible to use this output again as input, because then the year is limited to 4 digits again. Tested with PHP 7.4.7 and 8.0-dev Test script: --------------- <?php $datetime1 = new \DateTimeImmutable('9999-01-02 15:00:00.000000', new \DateTimeZone('UTC')); try { $datetime2 = $datetime1->add(new \DateInterval('P1Y')); echo $datetime2->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; } $datetime3 = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', $datetime2->format('Y-m-d H:i:s.u'), new \DateTimeZone('UTC')); if ($datetime3 !== false) { echo $datetime3->format('Y-m-d H:i:s.u') . \PHP_EOL; } else { echo 'false' . \PHP_EOL; } try { $datetime4 = new \DateTimeImmutable($datetime2->format('Y-m-d H:i:s.u'), new \DateTimeZone('UTC')); echo $datetime4->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; } // Workaround with fake year try { $datetime5 = new \DateTimeImmutable($datetime2->format('1234-m-d H:i:s.u'), new \DateTimeZone('UTC')); $datetime5 = $datetime5->setDate((int)$datetime2->format("Y"), (int)$datetime2->format("n"), (int)$datetime2->format("j")); echo $datetime5->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; } Expected result: ---------------- Variant A ("Y" handled as 4+ digits, preferred): 10000-01-02 15:00:00.000000 10000-01-02 15:00:00.000000 10000-01-02 15:00:00.000000 10000-01-02 15:00:00.000000 Variant B ("Y" handled as 4 digits, following the behavior of "y" - if the support for the year zero in PHP is the expected behavior and not another bug): 0000-01-02 15:00:00.000000 0000-01-02 15:00:00.000000 0000-01-02 15:00:00.000000 0000-01-02 15:00:00.000000 Variant C (5-digit years not supported): exception false exception exception Actual result: -------------- 10000-01-02 15:00:00.000000 false exception 10000-01-02 15:00:00.000000 -- Edit bug report at https://bugs.php.net/bug.php?id=79717&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79717&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79717&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79717&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79717&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79717&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79717&r=support Expected behavior: https://bugs.php.net/fix.php?id=79717&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79717&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79717&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79717&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79717&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79717&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79717&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79717&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79717&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79717&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79717&r=mysqlcfg

« previous php.bugs (#227560) next »