Respect / Validation

The most awesome validation engine ever created for PHP
https://respect-validation.readthedocs.io
MIT License
5.75k stars 774 forks source link

Date-related rules are not working today #1443

Open henriquemoody opened 5 months ago

henriquemoody commented 5 months ago

This is probably an issue with PHP, not with the library itself. I can't wrap my head around it:

echo DateTime::createFromFormat('Ym', '202302')->format('Ym');
// Outputs 202303

I will create a commit to let the test pass for now, and I will get back to it whenever I can.


Another similar issue: https://github.com/henriquemoody/Validation/actions/runs/8103265516/job/22147529888

reima commented 5 months ago

This is caused by a combination of two non-intuitive behaviors of DateTime::createFromFormat:

This means that DateTime::createFromFormat('Ym', '202302') will use the current day of the month, e.g. the parsed date will be 2023-02-31 on January 31st. The overflow behavior "corrects" this to 2023-03-03.

Prefixing the format string with "!" will set missing fields to sensible, fixed default values (i.e. 1 for the day).

henriquemoody commented 5 months ago

Thank you for such detailed answer, @reima!

ayurenia-seedbox commented 1 month ago

Hello @henriquemoody !

Could you please provide status on this issue? I believe in 2.3.7 bug were still present?

Thanks, Anna