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

#17642 - Reset day parameter when using Y-m #20566

Merged
merged 2 commits into from
Aug 14, 2017
Merged

#17642 - Reset day parameter when using Y-m #20566

merged 2 commits into from
Aug 14, 2017

Conversation

BramRoets
Copy link
Contributor

This should fix #17642

Note: this bug only happens when the computers date is set to 31/xx/xxx (or any date not existing in february)

@taylorotwell taylorotwell merged commit f974e89 into laravel:5.4 Aug 14, 2017
@arjasco
Copy link
Contributor

arjasco commented Aug 23, 2017

@taylorotwell @BramRoets Unfortunately. This still doesn't fix the problem, it's making the assumption your format will be Y-m when the problem occurs. Thats not the case because when using m-Y or Y/m or whatever takes your fancy, it will still occur.

My pull request back in January #17693 did solve the problem but got closed :(

$date = DateTime::createFromFormat('!' . $parameters[0], $value);

Thats all it takes, I'm not sure why we can't just go with this, remove the extra test and thats the problem solved.

@rtheunissen
Copy link
Contributor

rtheunissen commented Aug 30, 2017

@taylorotwell this bug is causing our app to crash badly today. It's the 31st of August today, which means that any month that doesn't have 31 days fails validation. The format we're using is F Y, but June 2017 fails because createFromFormat returns July 2017.

The solution to prefix ! works as far as I can tell. The PHP documentation says:

Without !, all fields will be set to the current date and time.

@arjasco was on point here and his closed PR should be merged asap.

@rtheunissen
Copy link
Contributor

rtheunissen commented Aug 31, 2017

We're currently using this as an interim solution.

Is it necessary to check that the date equals the value? Surely if it could be resolved at all should be sufficient?

$validator->extend('hotfix_date_format', function ($attribute, $value, $parameters, $validator) {
    return (is_string($value) || is_numeric($value))
        && (DateTime::createFromFormat($parameters[0], $value) !== false);
});

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

Successfully merging this pull request may close these issues.

4 participants