Bug #79716 [NEW]: Invalid date time created (with day "00")
| From: | a dot schilder at gmx dot de | Date: | Fri, 19 Jun 2020 13:07:15 +0000 |
| Subject: | Bug #79716 [NEW]: Invalid date time created (with day "00") | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227556@lists.php.net to get a copy of this message | ||
From: a dot schilder at gmx dot de
Operating system: Windows 10
PHP version: 7.4.7
Package: Date/time related
Bug Type: Bug
Bug description:Invalid date time created (with day "00")
Description:
------------
Situation:
I'm doing some datetiem calculations. I have a start date time and
calculate following dates based on recurrence rules. This means I add
date intervals to the start date time value until a specific date time
or number of results. Depending on the rule the date can be hundreds oy
years in the future.
Error:
From time to time I got an error when trying to get the number of days
in month of the resulting date time. The value I got was "0" (which
isn't documented, because it shouldn't be possible). When I dum the
object, the internal date time value is set to the invalid date
"2770-01-00 15:00:00.000000".
I can't say how it came to the result, because there were too many date
intervals added to the start date time, but it's easy to reproduced by
creating a date time instance directly with this wrong time value.
Reproduced in the following PHP Versions:
7.2.2, 7.4.2, 7.4.7, 8.0.0-dev
Test script:
---------------
<?php
$datetime = new \DateTimeImmutable(
'2770-01-00 15:00:00.000000',
new \DateTimeZone('UTC')
);
\var_dump($datetime->format('j') === '0');
\var_dump($datetime);
Expected result:
----------------
bool(false)
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2769-12-31 15:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
Actual result:
--------------
bool(true)
object(DateTimeImmutable)#3 (3) {
["date"]=>
string(26) "2770-01-00 15:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=79716&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79716&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79716&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79716&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79716&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79716&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79716&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79716&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79716&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79716&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79716&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79716&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79716&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79716&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79716&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79716&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79716&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79716&r=mysqlcfg