Skip to content

Commit

Permalink
fix for leap year
Browse files Browse the repository at this point in the history
  • Loading branch information
demeritcowboy committed Feb 26, 2024
1 parent a43333e commit 64b9f87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/phpunit/api/v4/Action/ContactGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ public function testAge(): void {
->addWhere('last_name', '=', $lastName)
->addSelect('first_name', 'age_years', 'next_birthday', 'DAYSTOANNIV(birth_date)')
->execute()->indexBy('first_name');

$adjustForLeapYear = (new \IntlGregorianCalendar())->isLeapYear(date('Y')) && (date('m') === '02') && (date('d') === '26' || date('d') === '27' || date('d') === '28' || date('d') === '29');
$this->assertEquals(1, $result['abc']['age_years']);
$this->assertEquals(3, $result['abc']['next_birthday']);
$this->assertEquals(3, $result['abc']['DAYSTOANNIV:birth_date']);
$this->assertEquals($adjustForLeapYear ? 4 : 3, $result['abc']['next_birthday']);
$this->assertEquals($adjustForLeapYear ? 4 : 3, $result['abc']['DAYSTOANNIV:birth_date']);
$this->assertEquals(21, $result['def']['age_years']);
$this->assertEquals(0, $result['ghi']['age_years']);
$this->assertEquals(0, $result['ghi']['next_birthday']);
Expand Down

0 comments on commit 64b9f87

Please sign in to comment.