From df6fae547b738cadaf1506302ef4e62dcc95e07a Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 21 Jan 2021 19:52:14 -0600 Subject: [PATCH] Added polyfill to isBefore of Carbon 2 Signed-off-by: victor --- src/Rules/CurpPenultimateChar.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Rules/CurpPenultimateChar.php b/src/Rules/CurpPenultimateChar.php index cffbc41..b2ee170 100644 --- a/src/Rules/CurpPenultimateChar.php +++ b/src/Rules/CurpPenultimateChar.php @@ -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; + } }