Reputation: 2146
Laravel validator doesn't accept dates that are more than 20 years in the future:
Route::get('test', function() {
$input = ['date' => '2039-01-01'];
$rule = ['date' => 'date'];
$v = \Illuminate\Support\Facades\Validator::make($input, $rule);
return 'Fails: '.$v->fails();
});
The following example returns true, despite the fact that the date is correct. But when I change 2039 to 2037, it works. How can I do to make the validator always return false?
Upvotes: 0
Views: 306
Reputation: 198314
From Wikipedia on Unix time:
On systems where the representation of Unix time is as a signed 32-bit number, the representation will end after the completion of 2,147,483,647 (2^31 - 1) seconds from 00:00:00 on 1 January 1970, which will happen on 19 January, 2038 UTC, with the exact time depending on the unpredictable leap seconds. This is referred to as the "Year 2038 problem" where the 32-bit signed Unix time will overflow and will take the actual count to negative.
And from Laravel Validation docs:
date
The field under validation must be a valid date according to the
strtotime
PHP function.
This seems to depend on whether PHP is compiled to use 32-bit timestamps or 64-bit timestamps (see discussions here). If you have a 32-bit PHP, your only way forward would be to write your own validator, that doesn't depend on PHP's date parsing (or move over to a 64-bit PHP).
Upvotes: 3