@@ -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
@@ -414,31 +419,31 @@ public function testAgeNow(): void
414419
415420 public function testAgeFuture (): void
416421 {
417- TimeLegacy::setTestNow ('June 20, 2022 ' , ' America/Chicago ' );
422+ TimeLegacy::setTestNow ('June 20, 2022 ' );
418423 $ time = TimeLegacy::parse ('August 12, 2116 4:15:23pm ' );
419424
420425 $ this ->assertSame (0 , $ time ->getAge ());
421426 }
422427
423428 public function testGetAgeSameDayOfBirthday (): void
424429 {
425- TimeLegacy::setTestNow ('December 31, 2022 ' , ' America/Chicago ' );
430+ TimeLegacy::setTestNow ('December 31, 2022 ' );
426431 $ time = TimeLegacy::parse ('December 31, 2020 ' );
427432
428433 $ this ->assertSame (2 , $ time ->getAge ());
429434 }
430435
431436 public function testGetAgeNextDayOfBirthday (): void
432437 {
433- TimeLegacy::setTestNow ('January 1, 2022 ' , ' America/Chicago ' );
438+ TimeLegacy::setTestNow ('January 1, 2022 ' );
434439 $ time = TimeLegacy::parse ('December 31, 2020 ' );
435440
436441 $ this ->assertSame (1 , $ time ->getAge ());
437442 }
438443
439444 public function testGetAgeBeforeDayOfBirthday (): void
440445 {
441- TimeLegacy::setTestNow ('December 30, 2021 ' , ' America/Chicago ' );
446+ TimeLegacy::setTestNow ('December 30, 2021 ' );
442447 $ time = TimeLegacy::parse ('December 31, 2020 ' );
443448
444449 $ this ->assertSame (0 , $ time ->getAge ());
0 commit comments