Skip to content

Commit

Permalink
Merge pull request #8668 from kenjis/docs-time
Browse files Browse the repository at this point in the history
docs: small improvements to Time
  • Loading branch information
kenjis authored Mar 28, 2024
2 parents 1046de8 + db187b2 commit 2a63810
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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');

0 comments on commit 2a63810

Please sign in to comment.