Update date formatting and add null-safe checks for pivot dates

Revised the date normalization format to align with ISO standards and ensure consistency. Additionally, introduced null-safe checks for pivot dates to avoid potential errors when these values are unset. Updated related tests to reflect these changes.
This commit is contained in:
2025-04-02 11:35:47 +02:00
parent 89aed74355
commit 10f66afdcd
2 changed files with 7 additions and 6 deletions

View File

@@ -29,17 +29,18 @@ class RollingDateTest extends TestCase
self::assertEquals(RollingDate::T_YEAR_PREVIOUS_START, $actual->getRoll());
self::assertNull($actual->getFixedDate());
self::assertEquals($date->getPivotDate()->getTimestamp(), $actual->getPivotDate()->getTimestamp());
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
}
public function testNormalizationDenormalizationProcessWithPivotDate(): void
{
$date = new RollingDate(RollingDate::T_FIXED_DATE, $pivot = new \DateTimeImmutable('now'));
$date = new RollingDate(RollingDate::T_FIXED_DATE, $fixed = new \DateTimeImmutable('now'));
$actual = RollingDate::fromNormalized($date->normalize());
self::assertEquals(RollingDate::T_FIXED_DATE, $actual->getRoll());
self::assertEquals($pivot, $actual->getFixedDate());
self::assertEquals($date->getPivotDate()->getTimestamp(), $actual->getPivotDate()->getTimestamp());
self::assertEquals($fixed, $actual->getFixedDate());
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
}
}