| @@ 29-61 (lines=33) @@ | ||
| 26 | ||
| 27 | use Carbon\Carbon; |
|
| 28 | ||
| 29 | class AsylumExpirationDate |
|
| 30 | { |
|
| 31 | public static function is_valid($asylum_expiration_date = null) |
|
| 32 | { |
|
| 33 | if (is_null($asylum_expiration_date)) { |
|
| 34 | throw new \InvalidArgumentException('Please pass in the date that the asylum document expires on.'); |
|
| 35 | } |
|
| 36 | ||
| 37 | if (empty(trim($asylum_expiration_date))) { |
|
| 38 | throw new \InvalidArgumentException('Please pass in the date that the asylum document expires on.'); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Rule from Tim here is that he wants a asylum document to still be used |
|
| 43 | * to register a user on the date their asylum document expires. |
|
| 44 | */ |
|
| 45 | try { |
|
| 46 | $date = Carbon::createFromFormat('Y-m-d', $asylum_expiration_date, 'UTC')->startOfDay(); |
|
| 47 | if ($date->toDateString() === $asylum_expiration_date) { |
|
| 48 | $now = Carbon::now()->startOfDay(); |
|
| 49 | if ($date->gte($now)) { |
|
| 50 | return true; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } catch (\Exception $e) { |
|
| 54 | if ('Data missing' == $e->getMessage()) { |
|
| 55 | throw new \Exception('Please provide a asylum expiration data in YYYY-MM-DD format.'); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| 59 | return false; |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 29-61 (lines=33) @@ | ||
| 26 | ||
| 27 | use Carbon\Carbon; |
|
| 28 | ||
| 29 | class PassportExpirationDate |
|
| 30 | { |
|
| 31 | public static function is_valid($passport_expiration_date = null) |
|
| 32 | { |
|
| 33 | if (is_null($passport_expiration_date)) { |
|
| 34 | throw new \InvalidArgumentException('Please pass in the date that the passport expires on.'); |
|
| 35 | } |
|
| 36 | ||
| 37 | if (empty(trim($passport_expiration_date))) { |
|
| 38 | throw new \InvalidArgumentException('Please pass in the date that the passport expires on.'); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Rule from Tim here is that he wants a passport to still be used |
|
| 43 | * to register a user on the date their passport expires. |
|
| 44 | */ |
|
| 45 | try { |
|
| 46 | $date = Carbon::createFromFormat('Y-m-d', $passport_expiration_date, 'UTC')->startOfDay(); |
|
| 47 | if ($date->toDateString() === $passport_expiration_date) { |
|
| 48 | $now = Carbon::now()->startOfDay(); |
|
| 49 | if ($date->gte($now)) { |
|
| 50 | return true; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } catch (\Exception $e) { |
|
| 54 | if ('Data missing' == $e->getMessage()) { |
|
| 55 | throw new \Exception('Please provide a passport expiration data in YYYY-MM-DD format.'); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| 59 | return false; |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||