From 10f66afdcd18077f3a3bad628861e4714cdbf55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 2 Apr 2025 11:35:47 +0200 Subject: [PATCH] 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. --- .../ChillMainBundle/Service/RollingDate/RollingDate.php | 4 ++-- .../Tests/Services/RollingDate/RollingDateTest.php | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDate.php b/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDate.php index 876c9dea3..e2657cde5 100644 --- a/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDate.php +++ b/src/Bundle/ChillMainBundle/Service/RollingDate/RollingDate.php @@ -63,7 +63,7 @@ class RollingDate final public const T_YEAR_PREVIOUS_START = 'year_previous_start'; - private const NORMALIZATION_FORMAT = 'd-m-Y-H:i:s.u T'; + private const NORMALIZATION_FORMAT = 'Y-m-d-H:i:s.u e'; /** * @param string|self::T_* $roll @@ -95,7 +95,7 @@ class RollingDate return [ 'roll' => $this->getRoll(), 'fixed_date' => $this->getFixedDate()?->format(self::NORMALIZATION_FORMAT), - 'pivot_date' => $this->getPivotDate()->format(self::NORMALIZATION_FORMAT), + 'pivot_date' => $this->getPivotDate()?->format(self::NORMALIZATION_FORMAT), 'v' => 1, ]; } diff --git a/src/Bundle/ChillMainBundle/Tests/Services/RollingDate/RollingDateTest.php b/src/Bundle/ChillMainBundle/Tests/Services/RollingDate/RollingDateTest.php index 3c7d01360..bd80e9ae8 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/RollingDate/RollingDateTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/RollingDate/RollingDateTest.php @@ -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()); } + }