Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:5.4from
BramRoets:5.4
Aug 14, 2017
Merged

#17642 - Reset day parameter when using Y-m#20566
taylorotwell merged 2 commits into
laravel:5.4from
BramRoets:5.4

Conversation

@BramRoets

Copy link
Copy Markdown
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

arjasco commented Aug 23, 2017

Copy link
Copy Markdown
Contributor

@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

rtheunissen commented Aug 30, 2017

Copy link
Copy Markdown
Contributor

@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

rtheunissen commented Aug 31, 2017

Copy link
Copy Markdown
Contributor

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