Bug #79387 [NEW]: createFromFormat works wrong with incorrect dates
| From: | amriwman at gmail dot com | Date: | Mon, 16 Mar 2020 12:32:38 +0000 |
| Subject: | Bug #79387 [NEW]: createFromFormat works wrong with incorrect dates | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-226123@lists.php.net to get a copy of this message | ||
From: amriwman at gmail dot com
Operating system: linux
PHP version: 7.4.3
Package: Date/time related
Bug Type: Bug
Bug description:createFromFormat works wrong with incorrect dates
Description:
------------
Incorrect creation from incorrect dates with
DateTimeImmutable::createFromFormat
Test script:
---------------
try{
$date = '2021-31-31';
$date1 = \DateTimeImmutable::createFromFormat('Y-m-d',
$date);
var_dump($date1);
$date2 = new \DateTimeImmutable($date);
}catch (\Throwable $e){
var_dump($e->getMessage());
}
die;
Expected result:
----------------
Failed to parse time string (2021-31-31) at position 6 (6): Unexpected
character
Actual result:
--------------
php version 7.4.2
class DateTimeImmutable#905 (0) {
}
sometimes it's even such:
DateTimeImmutable @1690803734 {#905
date: 2023-07-31 11:42:14.0 UTC (+00:00)
}
php version 7.4.3
object(DateTimeImmutable)#985 (3) {
["date"]=>
string(26) "2023-07-31 14:26:58.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "Europe/Helsinki"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=79387&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79387&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79387&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79387&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79387&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79387&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79387&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79387&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79387&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79387&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79387&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79387&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79387&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79387&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79387&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79387&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79387&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79387&r=mysqlcfg