Date format validation #152

Closed
zhangyb opened this Issue Feb 21, 2014 · 1 comment

Comments

Projects
None yet
2 participants

zhangyb commented Feb 21, 2014

The Date validation rule does not accept "c" as a format parameter (as seen on date() function) because DateTime::createFromFormat does not recognise it.

The following should work:

<?php

use Respect\Validation\Validator as v;

v::date('c')->assert('2004-02-12T15:19:21+00:00'); // true

Original post

Ran into this issue earlier, so I thought I'd post an issue here so others who encounter the same problem have an idea whats going on.

If you try to validate a date format using the "c" format string, which is supposed to be the ISO 8601 date format:

$date_validator = v::date('c'); ,

it will fail because the code behind the Date validator uses DateTime::createFromFormat which doesn't support the "c" format string unfortunately.

The workaround for this is to specify the equivalent format using other format specifiers:

$date_validator = v::date('Y-m-d\TH:i:sP');

Date validator would be even more awesome if it detected exceptional format strings such as this one and do an internal translation automatically :)

Hope this helps someone else!

augustohp added this to the Backlog milestone Feb 24, 2014

Owner

augustohp commented Feb 24, 2014

Thanks to take the time @zhangyb! I can't agree more with you, it would be definitely more awesome to have that!

wesleyvicthor closed this in #211 Oct 6, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment