Skip to content

[Clock] Add $modifier argument to the now() helper #18771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/clock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,27 @@ The Clock component also provides the ``now()`` function::
// Get the current time as a DateTimeImmutable instance
$now = now();

The ``now()`` function takes an optional ``modifier`` argument
which will be applied to the current time::

$later = now('+3 hours');

$yesterday = now('-1 day');

You can use any string `accepted by the DateTime constructor`_.

Later on this page you can learn how to use this clock in your services and tests.

.. versionadded:: 6.3

The :class:`Symfony\\Component\\Clock\\Clock` class and ``now()`` function
were introduced in Symfony 6.3.

.. versionadded:: 6.4

The ``modifier`` argument of the ``now()`` function was introduced in
Symfony 6.4.

Available Clocks Implementations
--------------------------------

Expand Down Expand Up @@ -252,3 +266,4 @@ control on your time-sensitive code's behavior.
The :class:`Symfony\\Component\\Clock\\Test\\ClockSensitiveTrait` was introduced in Symfony 6.3.

.. _`PSR-20`: https://www.php-fig.org/psr/psr-20/
.. _`accepted by the DateTime constructor`: https://www.php.net/manual/en/datetime.formats.php