Skip to content

Commit

Permalink
Fixed issues with date
Browse files Browse the repository at this point in the history
  • Loading branch information
designbycode committed Jun 21, 2024
1 parent 49bc6f1 commit 30d83d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ Output:
Array
(
[valid] => 1
[birthday] => 1994/04/26
[birthday] => Arrya(
'default' => '1978-04-29',
'iso' => '1978-04-29',
'american' => '04/29/1978',
'european' => '04/29/1978',
'long' => 'April 29, 1978',
)
[age] => 28
[gender] => Male
[citizenship] => SA Citizen
Expand Down
4 changes: 2 additions & 2 deletions src/SouthAfricanIdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function parse($idNumber): array
$birthDate = $this->extractBirthDate($idNumber);

// Determine age
$age = $birthDate->diffInYears(Carbon::now());
$age = round($birthDate->diffInYears(Carbon::now()));

// Determine gender
$gender = $this->isMale($idNumber) ? 'Male' : 'Female';
Expand All @@ -105,7 +105,7 @@ public function parse($idNumber): array
return [
'valid' => $this->isValid($idNumber),
'birthday' => [
'default' => $birthDate,
'default' => $birthDate->toDateString(),
'iso' => $birthDate->format('Y-m-d'),
'american' => $birthDate->format('m/d/Y'),
'european' => $birthDate->format('d/m/Y'),
Expand Down
2 changes: 1 addition & 1 deletion tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
it('parses a valid ID number', function () {
$result = $this->validator->parse($this->id);
expect($result['valid'])->toBeTrue()
->and($result['birthday']['default'])->toBeInstanceOf(Carbon\Carbon::class)
->and($result['birthday']['default'])->toBeString(Carbon\Carbon::class)
->and($result['age'])->toBeGreaterThan(0)
->and($result['gender'])->toBeString()
->and($result['citizenship'])->toBeString();
Expand Down

0 comments on commit 30d83d6

Please sign in to comment.