createFromFormat($format, $value) too strict
impronta48 opened this issue · comments
I very often have this problem when I marshall my data.
If the datetime string is missing some elements (eg: seconds), the result of the createFromFormat is invalid.
I'd expect a behaviour similar to the original PHP https://www.php.net/manual/en/datetime.createfromformat.php
Where the missing values would be taken from the current timestamp or from unix epoch.
Here is my example
$format= "Y-m-d\TH:i:s"
$value= "2020-01-12T10:00"
createFromFormat($format, $value) returns ERROR
Using DateTime::createFromFormat()
for your example values also fails https://3v4l.org/0hrYi.
Chronos::createFromFormat()
simply calls the parent method DateTimeImmutable::createFromFormat()
. Only additional thing it does if throw an exception if object creation fails.
I highly doubt anyone would be interested in providing a more fault tolerant implementation of createFromFormat()
.