Skip to content

Commit

Permalink
Merge pull request #8884 from obozdag/patch-2
Browse files Browse the repository at this point in the history
docs: Some small typos and modifications in libraries/time.rst
  • Loading branch information
kenjis authored May 27, 2024
2 parents b999381 + 2e480d5 commit b1e2366
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions user_guide_src/source/libraries/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Times and Dates
###############

CodeIgniter provides a fully-localized, immutable, date/time class that is built on PHP's DateTimeImmutable object, but uses the Intl
CodeIgniter provides a fully-localized, immutable, date/time class that is built on PHP's DateTimeImmutable class, but uses the Intl
extension's features to convert times across timezones and display the output correctly for different locales. This class
is the ``Time`` class and lives in the ``CodeIgniter\I18n`` namespace.

Expand Down Expand Up @@ -34,9 +34,9 @@ This can be any string that PHP's `DateTimeImmutable`_ constructor can parse. Se

.. literalinclude:: time/001.php

You can pass in strings representing the timezone and the locale in the second and parameters, respectively. Timezones
can be any supported by PHP's `DateTimeZone <https://www.php.net/manual/en/timezones.php>`__ class. The locale can be
any supported by PHP's `Locale <https://www.php.net/manual/en/class.locale.php>`__ class. If no locale or timezone is
You can pass in strings representing the timezone and the locale in the second and the third parameters, respectively. The timezone
can be any one supported by PHP's `DateTimeZone <https://www.php.net/manual/en/timezones.php>`__ class. The locale can be
any one supported by PHP's `Locale <https://www.php.net/manual/en/class.locale.php>`__ class. If no locale or timezone is
provided, the application defaults will be used.

.. literalinclude:: time/002.php
Expand All @@ -45,8 +45,8 @@ now()
=====

The Time class has several helper methods to instantiate the class. The first of these is the ``now()`` method
that returns a new instance set to the current time. You can pass in strings representing the timezone and the locale
in the second and parameters, respectively. If no locale or timezone is provided, the application defaults will be used.
that returns a new instance set to the current time. You can pass in strings representing the timezone and locale
in the second and third parameters, respectively. If no locale or timezone is provided, the application defaults will be used.

.. literalinclude:: time/003.php

Expand Down Expand Up @@ -86,15 +86,15 @@ createFromDate()
================

Given separate inputs for **year**, **month**, and **day**, will return a new instance. If any of these parameters
are not provided, it will use the current value to fill it in. Accepts strings for the timezone and locale in the
are not provided, it will use the current year, month and day. Accepts strings for the timezone and locale in the
fourth and fifth parameters:

.. literalinclude:: time/008.php

createFromTime()
================

Like ``createFromDate()`` except it is only concerned with the **hours**, **minutes**, and **seconds**. Uses the
Like ``createFromDate()``, except it is only concerned with the **hours**, **minutes**, and **seconds**. Uses the
current day for the date portion of the Time instance. Accepts strings for the timezone and locale in the
fourth and fifth parameters:

Expand All @@ -104,7 +104,7 @@ create()
========

A combination of the previous two methods, takes **year**, **month**, **day**, **hour**, **minutes**, and **seconds**
as separate parameters. Any value not provided will use the current date and time to determine. Accepts strings for the
as separate parameters. Any value not provided will use the current date and time. Accepts strings for the
timezone and locale in the fourth and fifth parameters:

.. literalinclude:: time/010.php
Expand Down Expand Up @@ -178,21 +178,21 @@ This will return a localized version of string formatted as (``Y-m-d H:i:s``):
toDateString()
==============

Displays just the localized version of date portion of the Time:
Displays just the localized date portion of the Time:

.. literalinclude:: time/017.php

toTimeString()
==============

Displays just the localized version of time portion of the value:
Displays just the localized time portion of the value:

.. literalinclude:: time/018.php

humanize()
==========

This methods returns a string that displays the difference between the current date/time and the instance in a
This method returns a string that displays the difference between the current date/time and the instance in a
human readable format that is geared towards being easily understood. It can create strings like '3 hours ago',
'in 1 month', etc:

Expand All @@ -203,17 +203,18 @@ The exact time displayed is determined in the following manner:
=============================== =================================
Time difference Result
=============================== =================================
$time > 1 year && < 2 years in 1 year / 1 year ago
$time > 1 month && < 1 year in 6 months / 6 months ago
$time > 7 days && < 1 month in 3 weeks / 3 weeks ago
$time > today && < 7 days in 4 days / 4 days ago
$time == tomorrow / yesterday Tomorrow / Yesterday
$time > 59 minutes && < 1 day in 2 hours / 2 hours ago
$time > now && < 1 hour in 35 minutes / 35 minutes ago
1 year < $time < 2 years in 1 year / 1 year ago
1 month < $time < 1 year in 6 months / 6 months ago
7 days < $time < 1 month in 3 weeks / 3 weeks ago
today < $time < 7 days in 4 days / 4 days ago
$time == yesterday / tomorrow Yesterday / Tomorrow
59 minutes < $time < 1 day in 2 hours / 2 hours ago
now < $time < 1 hour in 35 minutes / 35 minutes ago
$time == now Now
=============================== =================================

The exact language used is controlled through the language file, **Time.php**.
The result strings are coming from the language file, **system/Language/en/Time.php**.
If you want to overwrite them, create **app/Language/{locale}/Time.php**.

******************************
Working with Individual Values
Expand All @@ -240,7 +241,7 @@ In addition to these, a number of methods exist to provide additional informatio
getAge()
--------

Returns the age, in years, of between the Time's instance and the current time. Perfect for checking
Returns the age, in years, between the Time instance and the current time. Perfect for checking
the age of someone based on their birthday:

.. literalinclude:: time/022.php
Expand Down Expand Up @@ -402,7 +403,7 @@ humanize()

Much like Time's ``humanize()`` method, this returns a string that displays the difference between the times in a
human readable format that is geared towards being easily understood. It can create strings like '3 hours ago',
'in 1 month', etc. The biggest differences are in how very recent dates are handled:
'in 1 month', etc. The biggest difference is in how very recent dates are handled:

.. literalinclude:: time/041.php

Expand All @@ -411,13 +412,14 @@ The exact time displayed is determined in the following manner:
=============================== =================================
Time difference Result
=============================== =================================
$time > 1 year && < 2 years in 1 year / 1 year ago
$time > 1 month && < 1 year in 6 months / 6 months ago
$time > 7 days && < 1 month in 3 weeks / 3 weeks ago
$time > today && < 7 days in 4 days / 4 days ago
$time > 1 hour && < 1 day in 8 hours / 8 hours ago
$time > 1 minute && < 1 hour in 35 minutes / 35 minutes ago
1 year < $time < 2 years in 1 year / 1 year ago
1 month < $time < 1 year in 6 months / 6 months ago
7 days < $time < 1 month in 3 weeks / 3 weeks ago
today < $time < 7 days in 4 days / 4 days ago
1 hour < $time < 1 day in 8 hours / 8 hours ago
1 minute < $time < 1 hour in 35 minutes / 35 minutes ago
$time < 1 minute Now
=============================== =================================

The exact language used is controlled through the language file, **Time.php**.
The result strings are coming from the language file, **system/Language/en/Time.php**.
If you want to overwrite them, create **app/Language/{locale}/Time.php**.

0 comments on commit b1e2366

Please sign in to comment.