Skip to content

Commit 5031e42

Browse files
committed
minor #18827 [Clock] Add support for DateMalformedStringException and DateInvalidTimeZoneException (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [Clock] Add support for `DateMalformedStringException` and `DateInvalidTimeZoneException` Fix #18758 Commits ------- c458428 [Clock] Add support for `DateMalformedStringException` and `DateInvalidTimeZoneException`
2 parents 40667c8 + c458428 commit 5031e42

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

components/clock.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,34 @@ control on your time-sensitive code's behavior.
265265

266266
The :class:`Symfony\\Component\\Clock\\Test\\ClockSensitiveTrait` was introduced in Symfony 6.3.
267267

268+
Exceptions Management
269+
---------------------
270+
271+
The Clock component takes full advantage of `the new DateTime exceptions`_
272+
introduced in PHP 8.3: ``DateMalformedStringException`` and
273+
``DateInvalidTimeZoneException``. These exceptions will be thrown
274+
respectively when a invalid string is passed to a clock (e.g. when
275+
creating a clock or modifying a ``MockClock``) and when an invalid timezone is
276+
used::
277+
278+
$userInput = 'invalid timezone';
279+
280+
try {
281+
$clock = Clock::get()->withTimeZone($userInput);
282+
} catch (\DateInvalidTimeZoneException $exception) {
283+
// ...
284+
}
285+
286+
Thanks to the `symfony/polyfill-php83`_ dependency required by the Clock
287+
component, you don't even need to run PHP 8.3 to enjoy these new explicit
288+
and consistent exceptions when using the Clock component.
289+
290+
.. versionadded:: 6.4
291+
292+
The support for ``DateMalformedStringException`` and
293+
``DateInvalidTimeZoneException`` was introduced in Symfony 6.4.
294+
268295
.. _`PSR-20`: https://www.php-fig.org/psr/psr-20/
269296
.. _`accepted by the DateTime constructor`: https://www.php.net/manual/en/datetime.formats.php
297+
.. _`the new DateTime exceptions`: https://wiki.php.net/rfc/datetime-exceptions
298+
.. _`symfony/polyfill-php83`: https://github.com/symfony/polyfill-php83

0 commit comments

Comments
 (0)