type = DiscountType::AMOUNT; $discount->value = DiscountValue::fromAmount(Money::EUR(100)); $discount->is_old_price_displayed = true; $discount->date_start = $parisStart; $discount->date_end = $parisEnd; // WHEN $discount->saveOrFail(); $rawRow = DB::table('discounts')->where('id', $discount->id)->first(); $reloaded = Discount::query()->findOrFail($discount->id); // THEN expect($rawRow?->date_start)->toBe('2026-05-04 14:00:00') ->and($rawRow?->date_end)->toBe('2026-11-02 14:30:00') ->and($reloaded->date_start?->timezoneName)->toBe('UTC') ->and($reloaded->date_start?->format('Y-m-d H:i:s'))->toBe('2026-05-04 14:00:00') ->and($reloaded->date_end?->format('Y-m-d H:i:s'))->toBe('2026-11-02 14:30:00'); }); it('normalizes offset-aware ISO strings and CarbonImmutable to UTC and preserves null values', function (): void { // GIVEN $cast = new UtcDatetimeCast(); $model = new Discount(); $parisImmutable = CarbonImmutable::parse('2026-05-04 16:00:00', 'Europe/Paris'); // WHEN $storedImmutable = $cast->set($model, 'date_start', $parisImmutable, []); $storedIso = $cast->set($model, 'date_start', '2026-07-10T10:15:00+02:00', []); $storedNull = $cast->set($model, 'date_start', null, []); $readNull = $cast->get($model, 'date_start', null, []); // THEN expect($storedImmutable)->toBe('2026-05-04 14:00:00') ->and($storedIso)->toBe('2026-07-10 08:15:00') ->and($storedNull)->toBeNull() ->and($readNull)->toBeNull(); }); });