Skip to content

Commit 8a8a67c

Browse files
committed
docs: add note for DST and Time::difference()
1 parent bb201e6 commit 8a8a67c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: user_guide_src/source/libraries/time.rst

+9
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ the original time:
379379

380380
.. literalinclude:: time/039.php
381381

382+
.. note:: Prior to v4.4.7, Time always converted the time zones to UTC before
383+
comparison. This could lead to unexpected results when containing a day
384+
differed from 24 hours due to Daylight Saving Time (DST).
385+
386+
Starting with v4.4.7, when comparing date/times that are in the same
387+
time zone, the comparison is performed as is, without conversion to UTC.
388+
389+
.. literalinclude:: time/042.php
390+
382391
You can use either ``getX()`` methods, or access the calculate values as if they were properties:
383392

384393
.. literalinclude:: time/040.php

Diff for: user_guide_src/source/libraries/time/042.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
// 31 Mar 2024 - Daylight Saving Time Starts
6+
$current = Time::parse('2024-03-31', 'Europe/Madrid');
7+
$test = Time::parse('2024-04-01', 'Europe/Madrid');
8+
9+
$diff = $current->difference($test);
10+
11+
echo $diff->getDays(); // 0 in v4.4.6 or before
12+
// 1 in v4.4.7 or later

0 commit comments

Comments
 (0)