Skip to content
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

docs: small improvements to Time #8668

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions user_guide_src/source/libraries/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ extension's features to convert times across timezones and display the output co
is the ``Time`` class and lives in the ``CodeIgniter\I18n`` namespace.

.. note:: Since the Time class extends ``DateTimeImmutable``, if there are features that you need that this class doesn't provide,
you can likely find them within the `DateTimeImmutable <https://www.php.net/manual/en/class.datetimeimmutable.php>`_ class itself.
you can likely find them within the `DateTimeImmutable`_ class itself.

.. _DateTimeImmutable: https://www.php.net/manual/en/class.datetimeimmutable.php

.. note:: Prior to v4.3.0, the Time class extended ``DateTime`` and some inherited methods changed
the current object state. The bug was fixed in v4.3.0. If you need the old Time class for backward
Expand All @@ -24,10 +26,11 @@ Instantiating
There are several ways that a new Time instance can be created. The first is simply to create a new instance
like any other class.

When you do it this way, you can pass in a string representing the desired time. This can
be any string that PHP's `strtotime()`_ function can parse:
When you do it this way, you can pass in a string representing the desired time.
This can be any string that PHP's `DateTimeImmutable`_ constructor can parse. See
`Supported Date and Time Formats`_ for details.

.. _strtotime(): https://www.php.net/manual/en/function.strtotime.php
.. _Supported Date and Time Formats: https://www.php.net/manual/en/datetime.formats.php

.. literalinclude:: time/001.php

Expand Down
4 changes: 3 additions & 1 deletion user_guide_src/source/libraries/time/001.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

use CodeIgniter\I18n\Time;

$myTime = new Time('+3 week');
$myTime = new Time('2024-01-01');
$myTime = new Time('2024-01-01 12:00:00');
$myTime = new Time('now');
$myTime = new Time('+3 week');