mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-28 21:16:13 +00:00
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:
parent
89aed74355
commit
10f66afdcd
@ -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,
|
||||
];
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user