Skip to content

Commit

Permalink
docs: add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 28, 2024
1 parent d8502af commit d438d05
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
6 changes: 6 additions & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ with different arguments in before or after. See

.. _v460-interface-changes:

Time with Microseconds
----------------------

Fixed bugs that some methods in ``Time`` to lose microseconds have been fixed.
See :ref:`Upgrading Guide <upgrade-460-time-keeps-microseconds>` for details.

Interface Changes
=================

Expand Down
36 changes: 36 additions & 0 deletions user_guide_src/source/installation/upgrade_460.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,42 @@ See :ref:`ChangeLog <v460-behavior-changes-exceptions>` for details.

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

.. _upgrade-460-time-keeps-microseconds:

Time keeps Microseconds
=======================

In previous versions, :doc:`Time <../libraries/time>` lost microseconds in some
cases. But the bugs have been fixed.

The results of the ``Time`` comparison may differ due to these fixes:

.. literalinclude:: upgrade_460/006.php
:lines: 2-

In a such case, you need to remove the microseconds:

.. literalinclude:: upgrade_460/007.php
:lines: 2-

The following cases now keeps microseconds:

.. literalinclude:: upgrade_460/002.php
:lines: 2-

.. literalinclude:: upgrade_460/003.php
:lines: 2-

Note that ``Time`` with the current time has been holding microseconds since before.

.. literalinclude:: upgrade_460/004.php
:lines: 2-

Also, methods that returns an ``int`` still lose the microseconds.

.. literalinclude:: upgrade_460/005.php
:lines: 2-

Interface Changes
=================

Expand Down
8 changes: 8 additions & 0 deletions user_guide_src/source/installation/upgrade_460/002.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::createFromFormat('Y-m-d H:i:s.u', '2024-07-09 09:13:34.654321');
echo $time->format('Y-m-d H:i:s.u');
// Before: 2024-07-09 09:13:34.000000
// After: 2024-07-09 09:13:34.654321
8 changes: 8 additions & 0 deletions user_guide_src/source/installation/upgrade_460/003.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use CodeIgniter\I18n\Time;

$time = new Time('1 hour ago');
echo $time->format('Y-m-d H:i:s.u');
// Before: 2024-07-26 21:05:57.000000
// After: 2024-07-26 21:05:57.857235
8 changes: 8 additions & 0 deletions user_guide_src/source/installation/upgrade_460/004.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::now();
echo $time->format('Y-m-d H:i:s.u');
// Before: 2024-07-26 21:39:32.249072
// After: 2024-07-26 21:39:32.249072
9 changes: 9 additions & 0 deletions user_guide_src/source/installation/upgrade_460/005.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = new Time('2024-01-01 12:00:00');
echo $time1->getTimestamp(); // 1704110400

$time2 = new Time('2024-01-01 12:00:00.654321');
echo $time2->getTimestamp(); // 1704110400
10 changes: 10 additions & 0 deletions user_guide_src/source/installation/upgrade_460/006.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = new Time('2024-01-01 12:00:00.654321');
$time2 = new Time('2024-01-01 12:00:00');

$time1->equals($time2);
// Before: true
// After: false
17 changes: 17 additions & 0 deletions user_guide_src/source/installation/upgrade_460/007.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = new Time('2024-01-01 12:00:00.654321');
$time2 = new Time('2024-01-01 12:00:00');

// Removes the microseconds.
$time1 = Time::createFromFormat(
'Y-m-d H:i:s',
$time1->format('Y-m-d H:i:s'),
$time1->getTimezone()
);

$time1->equals($time2);
// Before: true
// After: true

0 comments on commit d438d05

Please sign in to comment.