Editor Format::dateFormatToSql when not setting all data
Editor Format::dateFormatToSql when not setting all data
gboussin
Posts: 13Questions: 4Answers: 0
in Bug reports
Dear all,
In Editor last version, in Editor/Format.php, beware if using dateFormatToSql with a format not including all date and time information: the function date_create_from_format is using the current time for missing data. It can create data inconsistencies.
For further versions, Allan, I suggest you add "!" in the following, as explained in http://php.net/manual/fr/datetime.createfromformat.php :
$date = date_create_from_format('!'.$format, $val);
Regards,
Gilles Boussin
This discussion has been closed.
Answers
Hi Gilles,
Thanks! Completely agree - thanks for pointing that out. I've committed a fix here.
Allan
Thanks!
Dear Allan,
I have had another occurence of this bug, so I checked the whole code :
you have to patch another date_create_from_format and you have 2 \DateTime::createFromFormat
Regards,
Gilles
I explain exactly why this is important:
if you have 02/2019 as m/Y, and you are today on the 30th of a month.
If you do not have the ! in front of format, the createFromFormat considers by default the day of today, so it takes the date 30/02/2019 which gives finally 03/2019 instead of 02/2019...
Good points - thanks! Fixed here.
Allan