Skip to content

Commit 4932e44

Browse files
committed
docs: add docs
1 parent f3b15c0 commit 4932e44

File tree

8 files changed

+102
-0
lines changed

8 files changed

+102
-0
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
@@ -59,6 +59,12 @@ executed twice, an exception will be thrown. See
5959

6060
.. _v460-interface-changes:
6161

62+
Time with Microseconds
63+
----------------------
64+
65+
Fixed bugs that some methods in ``Time`` to lose microseconds have been fixed.
66+
See :ref:`Upgrading Guide <upgrade-460-time-keeps-microseconds>` for details.
67+
6268
Interface Changes
6369
=================
6470

user_guide_src/source/installation/upgrade_460.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ See :ref:`ChangeLog <v460-behavior-changes-exceptions>` for details.
2929

3030
If you have code that catches these exceptions, change the exception classes.
3131

32+
.. _upgrade-460-time-keeps-microseconds:
33+
34+
Time keeps Microseconds
35+
=======================
36+
37+
In previous versions, :doc:`Time <../libraries/time>` lost microseconds in some
38+
cases. But the bugs have been fixed.
39+
40+
The results of the ``Time`` comparison may differ due to these fixes:
41+
42+
.. literalinclude:: upgrade_460/006.php
43+
:lines: 2-
44+
45+
In a such case, you need to remove the microseconds:
46+
47+
.. literalinclude:: upgrade_460/007.php
48+
:lines: 2-
49+
50+
The following cases now keeps microseconds:
51+
52+
.. literalinclude:: upgrade_460/002.php
53+
:lines: 2-
54+
55+
.. literalinclude:: upgrade_460/003.php
56+
:lines: 2-
57+
58+
Note that ``Time`` with the current time has been holding microseconds since before.
59+
60+
.. literalinclude:: upgrade_460/004.php
61+
:lines: 2-
62+
63+
Also, methods that returns an ``int`` still lose the microseconds.
64+
65+
.. literalinclude:: upgrade_460/005.php
66+
:lines: 2-
67+
3268
.. _upgrade-460-registrars-with-dirty-hack:
3369

3470
Registrars with Dirty Hack
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time = Time::createFromFormat('Y-m-d H:i:s.u', '2024-07-09 09:13:34.654321');
6+
echo $time->format('Y-m-d H:i:s.u');
7+
// Before: 2024-07-09 09:13:34.000000
8+
// After: 2024-07-09 09:13:34.654321
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time = new Time('1 hour ago');
6+
echo $time->format('Y-m-d H:i:s.u');
7+
// Before: 2024-07-26 21:05:57.000000
8+
// After: 2024-07-26 21:05:57.857235
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time = Time::now();
6+
echo $time->format('Y-m-d H:i:s.u');
7+
// Before: 2024-07-26 21:39:32.249072
8+
// After: 2024-07-26 21:39:32.249072
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time1 = new Time('2024-01-01 12:00:00');
6+
echo $time1->getTimestamp(); // 1704110400
7+
8+
$time2 = new Time('2024-01-01 12:00:00.654321');
9+
echo $time2->getTimestamp(); // 1704110400
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time1 = new Time('2024-01-01 12:00:00.654321');
6+
$time2 = new Time('2024-01-01 12:00:00');
7+
8+
$time1->equals($time2);
9+
// Before: true
10+
// After: false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use CodeIgniter\I18n\Time;
4+
5+
$time1 = new Time('2024-01-01 12:00:00.654321');
6+
$time2 = new Time('2024-01-01 12:00:00');
7+
8+
// Removes the microseconds.
9+
$time1 = Time::createFromFormat(
10+
'Y-m-d H:i:s',
11+
$time1->format('Y-m-d H:i:s'),
12+
$time1->getTimezone()
13+
);
14+
15+
$time1->equals($time2);
16+
// Before: true
17+
// After: true

0 commit comments

Comments
 (0)