Skip to content

Commit 549db02

Browse files
committed
test: fix tests that fails on Feb 29
1 parent 9894b92 commit 549db02

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

tests/system/I18n/TimeLegacyTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,15 @@ public function testGetTimestamp(): void
399399

400400
public function testGetAge(): void
401401
{
402+
// setTestNow() does not work to parse().
402403
$time = TimeLegacy::parse('5 years ago');
403404

404-
$this->assertSame(5, $time->getAge());
405-
$this->assertSame(5, $time->age);
405+
// Considers leap year
406+
$now = TimeLegacy::now();
407+
$expected = ($now->day === '29' && $now->month === '2') ? 4 : 5;
408+
409+
$this->assertSame($expected, $time->getAge());
410+
$this->assertSame($expected, $time->age);
406411
}
407412

408413
public function testAgeNow(): void

tests/system/I18n/TimeTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,15 @@ public function testGetTimestamp(): void
406406
*/
407407
public function testGetAge(): void
408408
{
409+
// setTestNow() does not work to parse().
409410
$time = Time::parse('5 years ago');
410411

411-
$this->assertSame(5, $time->getAge());
412-
$this->assertSame(5, $time->age);
412+
// Considers leap year
413+
$now = Time::now();
414+
$expected = ($now->day === '29' && $now->month === '2') ? 4 : 5;
415+
416+
$this->assertSame($expected, $time->getAge());
417+
$this->assertSame($expected, $time->age);
413418
}
414419

415420
public function testAgeNow(): void

0 commit comments

Comments
 (0)