Skip to content

Commit 3884480

Browse files
committed
docs: update user guide
1 parent 9395543 commit 3884480

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ Time with Microseconds
7171
Fixed bugs that some methods in ``Time`` to lose microseconds have been fixed.
7272
See :ref:`Upgrading Guide <upgrade-460-time-keeps-microseconds>` for details.
7373

74+
Time::setTimestamp()
75+
--------------------
76+
77+
``Time::setTimestamp()`` behavior has been fixed.
78+
See :ref:`Upgrading Guide <upgrade-460-time-set-timestamp>` for details.
79+
7480
.. _v460-interface-changes:
7581

7682
Interface Changes

user_guide_src/source/installation/upgrade_460.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ Also, methods that returns an ``int`` still lose the microseconds.
8585
.. literalinclude:: upgrade_460/005.php
8686
:lines: 2-
8787

88+
.. _upgrade-460-time-set-timestamp:
89+
90+
Time::setTimestamp() Behavior Fix
91+
=================================
92+
93+
In previous versions, if you call ``Time::setTimestamp()`` on a Time instance with
94+
a timezone other than the default timezone might return a Time instance with the
95+
wrong date/time.
96+
97+
This bug has been fixed, and it now behaves in the same way as ``DateTimeImmutable``:
98+
99+
.. literalinclude:: upgrade_460/008.php
100+
:lines: 2-
101+
102+
Note that if you use the default timezone, the behavior is not changed:
103+
104+
.. literalinclude:: upgrade_460/009.php
105+
:lines: 2-
106+
88107
.. _upgrade-460-registrars-with-dirty-hack:
89108

90109
Registrars with Dirty Hack
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
// The Application Timezone is "UTC".
6+
7+
// Set $time1 timezone to "America/Chicago".
8+
$time1 = Time::parse('2024-08-20', 'America/Chicago');
9+
10+
// The timestamp is "2024-08-20 00:00" in "UTC".
11+
$stamp = strtotime('2024-08-20'); // 1724112000
12+
13+
// But $time2 timezone is "America/Chicago".
14+
$time2 = $time1->setTimestamp($stamp);
15+
16+
echo $time2->format('Y-m-d H:i:s P');
17+
// Before: 2024-08-20 00:00:00 -05:00
18+
// After: 2024-08-19 19:00:00 -05:00
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
// The Application Timezone is "America/Chicago".
6+
7+
// $time1 timezone is "America/Chicago".
8+
$time1 = Time::parse('2024-08-20');
9+
10+
// The timestamp is "2024-08-20 00:00" in "America/Chicago".
11+
$stamp = strtotime('2024-08-20'); // 1724130000
12+
13+
// $time2 timezone is also "America/Chicago".
14+
$time2 = $time1->setTimestamp($stamp);
15+
16+
echo $time2->format('Y-m-d H:i:s P');
17+
// Before: 2024-08-20 00:00:00 -05:00
18+
// After: 2024-08-20 00:00:00 -05:00

user_guide_src/source/libraries/time.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ Returns a new instance with the date set to the new timestamp:
314314

315315
.. literalinclude:: time/030.php
316316

317+
.. note:: Prior to v4.6.0, due to a bug, this method might return incorrect
318+
date/time. See :ref:`Upgrading Guide <upgrade-460-time-set-timestamp>` for details.
319+
317320
Modifying the Value
318321
===================
319322

user_guide_src/source/libraries/time/030.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
use CodeIgniter\I18n\Time;
44

5-
$time = Time::parse('May 10, 2017', 'America/Chicago');
5+
// The Application Timezone is "America/Chicago".
6+
7+
$time = Time::parse('May 10, 2017');
68
$time2 = $time->setTimestamp(strtotime('April 1, 2017'));
79

810
echo $time->toDateTimeString(); // 2017-05-10 00:00:00

0 commit comments

Comments
 (0)