Skip to content

Commit

Permalink
Added polyfill to isBefore of Carbon 2
Browse files Browse the repository at this point in the history
Signed-off-by: victor <[email protected]>
  • Loading branch information
victor-c4uno committed Jan 22, 2021
1 parent 8ea39ab commit df6fae5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Rules/CurpPenultimateChar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,26 @@ public function message()

private function getRegexp(Carbon $date)
{
if ($date->isBefore(Carbon::parse('2000-01-01 00:00:00'))) {
// Fix to Carbon < 2


if ($this->isBefore($date)) {
return '/^.{16}\d/i';
}

return '/^.{16}[a-z]{1}/i';
}

/**
* Carbon 1.* does not has isBefore function
*/
private function isBefore(Carbon $date): bool
{
$limit = Carbon::parse('2000-01-01 00:00:00');
if (method_exists($date, 'isBefore')) {
return $date->isBefore($limit);
}

return $date->diffInDays($limit, false) > 0;
}
}

0 comments on commit df6fae5

Please sign in to comment.