Editor Format::dateFormatToSql when not setting all data

Editor Format::dateFormatToSql when not setting all data

gboussingboussin Posts: 13Questions: 4Answers: 0

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

Answers

  • allanallan Posts: 61,615Questions: 1Answers: 10,089 Site admin

    Hi Gilles,

    Thanks! Completely agree - thanks for pointing that out. I've committed a fix here.

    Allan

  • gboussingboussin Posts: 13Questions: 4Answers: 0

    Thanks!

  • gboussingboussin Posts: 13Questions: 4Answers: 0

    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

  • gboussingboussin Posts: 13Questions: 4Answers: 0

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

  • allanallan Posts: 61,615Questions: 1Answers: 10,089 Site admin

    Good points - thanks! Fixed here.

    Allan

This discussion has been closed.