diff --git a/tests/system/I18n/TimeLegacyTest.php b/tests/system/I18n/TimeLegacyTest.php index 36907988349d..5814683ba6c7 100644 --- a/tests/system/I18n/TimeLegacyTest.php +++ b/tests/system/I18n/TimeLegacyTest.php @@ -399,10 +399,15 @@ public function testGetTimestamp(): void public function testGetAge(): void { + // setTestNow() does not work to parse(). $time = TimeLegacy::parse('5 years ago'); - $this->assertSame(5, $time->getAge()); - $this->assertSame(5, $time->age); + // Considers leap year + $now = TimeLegacy::now(); + $expected = ($now->day === '29' && $now->month === '2') ? 4 : 5; + + $this->assertSame($expected, $time->getAge()); + $this->assertSame($expected, $time->age); } public function testAgeNow(): void @@ -414,7 +419,7 @@ public function testAgeNow(): void public function testAgeFuture(): void { - TimeLegacy::setTestNow('June 20, 2022', 'America/Chicago'); + TimeLegacy::setTestNow('June 20, 2022'); $time = TimeLegacy::parse('August 12, 2116 4:15:23pm'); $this->assertSame(0, $time->getAge()); @@ -422,7 +427,7 @@ public function testAgeFuture(): void public function testGetAgeSameDayOfBirthday(): void { - TimeLegacy::setTestNow('December 31, 2022', 'America/Chicago'); + TimeLegacy::setTestNow('December 31, 2022'); $time = TimeLegacy::parse('December 31, 2020'); $this->assertSame(2, $time->getAge()); @@ -430,7 +435,7 @@ public function testGetAgeSameDayOfBirthday(): void public function testGetAgeNextDayOfBirthday(): void { - TimeLegacy::setTestNow('January 1, 2022', 'America/Chicago'); + TimeLegacy::setTestNow('January 1, 2022'); $time = TimeLegacy::parse('December 31, 2020'); $this->assertSame(1, $time->getAge()); @@ -438,7 +443,7 @@ public function testGetAgeNextDayOfBirthday(): void public function testGetAgeBeforeDayOfBirthday(): void { - TimeLegacy::setTestNow('December 30, 2021', 'America/Chicago'); + TimeLegacy::setTestNow('December 30, 2021'); $time = TimeLegacy::parse('December 31, 2020'); $this->assertSame(0, $time->getAge()); diff --git a/tests/system/I18n/TimeTest.php b/tests/system/I18n/TimeTest.php index d60fb4410a03..db34590eadeb 100644 --- a/tests/system/I18n/TimeTest.php +++ b/tests/system/I18n/TimeTest.php @@ -406,10 +406,15 @@ public function testGetTimestamp(): void */ public function testGetAge(): void { + // setTestNow() does not work to parse(). $time = Time::parse('5 years ago'); - $this->assertSame(5, $time->getAge()); - $this->assertSame(5, $time->age); + // Considers leap year + $now = Time::now(); + $expected = ($now->day === '29' && $now->month === '2') ? 4 : 5; + + $this->assertSame($expected, $time->getAge()); + $this->assertSame($expected, $time->age); } public function testAgeNow(): void @@ -421,7 +426,7 @@ public function testAgeNow(): void public function testAgeFuture(): void { - Time::setTestNow('June 20, 2022', 'America/Chicago'); + Time::setTestNow('June 20, 2022'); $time = Time::parse('August 12, 2116 4:15:23pm'); $this->assertSame(0, $time->getAge()); @@ -429,7 +434,7 @@ public function testAgeFuture(): void public function testGetAgeSameDayOfBirthday(): void { - Time::setTestNow('December 31, 2022', 'America/Chicago'); + Time::setTestNow('December 31, 2022'); $time = Time::parse('December 31, 2020'); $this->assertSame(2, $time->getAge()); @@ -437,7 +442,7 @@ public function testGetAgeSameDayOfBirthday(): void public function testGetAgeNextDayOfBirthday(): void { - Time::setTestNow('January 1, 2022', 'America/Chicago'); + Time::setTestNow('January 1, 2022'); $time = Time::parse('December 31, 2020'); $this->assertSame(1, $time->getAge()); @@ -445,7 +450,7 @@ public function testGetAgeNextDayOfBirthday(): void public function testGetAgeBeforeDayOfBirthday(): void { - Time::setTestNow('December 30, 2021', 'America/Chicago'); + Time::setTestNow('December 30, 2021'); $time = Time::parse('December 31, 2020'); $this->assertSame(0, $time->getAge());