[php-src] Issue #10957: `DateTime::createFromFormat()` valid date mismatch
| From: | ddevsr | Date: | Tue, 28 Mar 2023 03:22:46 +0000 |
| Subject: | [php-src] Issue #10957: `DateTime::createFromFormat()` valid date mismatch | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244023@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10957
Author: ddevsr
### Description
For example, now date in my computer
28-03-2023 10:00 (d-m-Y H:i). I will set
$tanggal with format m-d-Y H:i and add 5 days from now will result
04-02-2023 XX:XX.
The following code:
```php
<?php
$tanggal = date('m-d-Y H:i');
$date = DateTime::createFromFormat('d-m-Y H:i', $tanggal);
$errors = DateTime::getLastErrors();
if ($date === false) {
return false;
}
// PHP 8.2 or later.
if ($errors === false) {
return true;
}
```
Resulted in this output:
```
format correct
```
But I expected this output instead:
```
format incorrect
```
```bash
$ vendor/bin/phpunit tests/app/Libraries/
PHPUnit 9.6.6 by Sebastian Bergmann and contributors.
Runtime: PHP 8.1.17 with Xdebug 3.2.1
Configuration: D:\Project\laragon\www\semangka\phpunit.xml.dist
Random Seed: 1679971894
...............F................................................. 65 / 72 ( 90%)
....... 72 / 72 (100%)
Time: 00:01.956, Memory: 24.00 MB
There was 1 failure:
1) SemangkaGatewayValidationTest::testFormatTanggalBerobat with data set #9 ('04-02-2023
02:51', false)
Failed asserting that true is identical to false.
D:\Project\laragon\www\semangka\tests\app\Libraries\SemangkaGatewayValidationTest.php:156
FAILURES!
Tests: 72, Assertions: 72, Failures: 1.
```
### PHP Version
8.1.17
### Operating System
Windows & Ubuntu 20.X