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: add note to Time::difference() and DST #8659

Closed
Closed
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
10 changes: 9 additions & 1 deletion user_guide_src/source/libraries/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ Viewing Differences
===================

To compare two Times directly, you would use the ``difference()`` method, which returns a ``CodeIgniter\I18n\TimeDifference``
instance. The first parameter is either a Time instance, a DateTime instance, or a string with the date/time. If
instance.

The first parameter is either a Time instance, a DateTime instance, or a string with the date/time. If
a string is passed in the first parameter, the second parameter can be a timezone string:

.. literalinclude:: time/038.php
Expand All @@ -377,6 +379,12 @@ the original time:

.. literalinclude:: time/039.php

.. note:: When calculating the difference in the number of days, unexpected results
may be returned if a day is not 24 hours long due to Daylight Saving Time
(DST).

.. literalinclude:: time/042.php

You can use either ``getX()`` methods, or access the calculate values as if they were properties:

.. literalinclude:: time/040.php
Expand Down
10 changes: 10 additions & 0 deletions user_guide_src/source/libraries/time/042.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use CodeIgniter\I18n\Time;

$current = Time::parse('2024-03-31', 'Europe/Madrid');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to this PR, but I recently read the documentation for Time::class.
The point is that dates in the database are commonly stored as yyyy-MM-dd HH:mm:ss, but there is no example of using this form in the document. I think you can use 2024-03-31 00:00:00 instead of 2024-03-31 .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent #8668

$test = Time::parse('2024-04-01', 'Europe/Madrid');

$diff = $current->difference($test);

echo $diff->getDays(); // 0