cakephp / chronos

A standalone DateTime library originally based off of Carbon

Home Page:http://book.cakephp.org/chronos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

commented

Using DateTime::createFromFormat() for your example values also fails https://3v4l.org/0hrYi.

commented

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().