Respect / Validation

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

DateTime validation fails on valid ISO-8601 timestamp #1439

Closed manuelmaurer closed 10 months ago

manuelmaurer commented 11 months ago

I'm trying to validate this json input: { "ts": "2019-02-08T09:04:05.317Z" } using this rule: v::key('ts', v::nullable(v::dateTime('c')))

Which fails, because it does not like the fractional second part (which PHP's DateTime does support). The source seems to be this conversion into a fixed format for the date_parse_from_format function call: https://github.com/Respect/Validation/blob/master/library/Helpers/CanValidateDateTime.php#L33

As the fractional part seems to be quite complicated in the standard, I'm not sure if this is an easy thing to fix. I'll try to play around a bit when I get the time.

henriquemoody commented 10 months ago

I'm sorry for my belated response!

Your date should work fine as long as you use the format that matches your date. In your case, that would be Y-m-d\TH:i:s.vp.

Here for more information: https://github.com/Respect/Validation/issues/1442#issuecomment-1915657084

If I misunderstood your request, feel free to reopen the issue. I'm here to help! 🐼