Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime rule not validating dates correctly #31

Closed
NickBelhomme opened this issue May 14, 2015 · 2 comments
Closed

DateTime rule not validating dates correctly #31

NickBelhomme opened this issue May 14, 2015 · 2 comments

Comments

@NickBelhomme
Copy link
Contributor

Context

When passing a format to the datetime rule, it even accepts dates which are in another format because of the default behavior of the \DateTime implementation.

Use Case

$validator->required('date')->datetime('Ymd');
$validator->validate(['date' => '12111978']); // 12 november 1978

The above will give true while 19 can never be a correct month, nor can 78 be a correct day.

The issue lies within this part of the code:

$date = date_create_from_format('Ymd', '11121978');
var_dump($date);

which gives:

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "1212-09-16 06:48:11.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(10) "US/Pacific"
}

https://github.com/particle-php/Validator/blob/master/src/Particle/Validator/Rule/Datetime.php#L75

Acceptance Criteria

When issuing a validation using the datetime rule, it must adhere to the format AND also verify if the date portions are the same. This ensures that the overflow is not used and dates such as above and
31-02-2015 are considered invalid.

@berry-langerak
Copy link
Member

That is a very excellent point, @NickBelhomme. I tend to forget this auto behaviour of \DateTime. Even though it can be helpful at times (start bill cycle on 29th of February == 1st of March), the functionality is not that useful when validating ;)

Will implement a fix soon!

@rick-nu
Copy link

rick-nu commented May 20, 2015

This bug is solved in #35 and is in version 0.4.0, closing.

@rick-nu rick-nu closed this as completed May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants