2
2
Times and Dates
3
3
###############
4
4
5
- CodeIgniter provides a fully-localized, immutable, date/time class that is built on PHP's DateTimeImmutable object , but uses the Intl
5
+ CodeIgniter provides a fully-localized, immutable, date/time class that is built on PHP's DateTimeImmutable class , but uses the Intl
6
6
extension's features to convert times across timezones and display the output correctly for different locales. This class
7
7
is the ``Time `` class and lives in the ``CodeIgniter\I18n `` namespace.
8
8
@@ -34,9 +34,9 @@ This can be any string that PHP's `DateTimeImmutable`_ constructor can parse. Se
34
34
35
35
.. literalinclude :: time/001.php
36
36
37
- You can pass in strings representing the timezone and the locale in the second and parameters, respectively. Timezones
38
- can be any supported by PHP's `DateTimeZone <https://www.php.net/manual/en/timezones.php >`__ class. The locale can be
39
- any supported by PHP's `Locale <https://www.php.net/manual/en/class.locale.php >`__ class. If no locale or timezone is
37
+ You can pass in strings representing the timezone and the locale in the second and the third parameters, respectively. The timezone
38
+ can be any one supported by PHP's `DateTimeZone <https://www.php.net/manual/en/timezones.php >`__ class. The locale can be
39
+ any one supported by PHP's `Locale <https://www.php.net/manual/en/class.locale.php >`__ class. If no locale or timezone is
40
40
provided, the application defaults will be used.
41
41
42
42
.. literalinclude :: time/002.php
45
45
=====
46
46
47
47
The Time class has several helper methods to instantiate the class. The first of these is the ``now() `` method
48
- that returns a new instance set to the current time. You can pass in strings representing the timezone and the locale
49
- in the second and parameters, respectively. If no locale or timezone is provided, the application defaults will be used.
48
+ that returns a new instance set to the current time. You can pass in strings representing the timezone and locale
49
+ in the second and third parameters, respectively. If no locale or timezone is provided, the application defaults will be used.
50
50
51
51
.. literalinclude :: time/003.php
52
52
@@ -86,15 +86,15 @@ createFromDate()
86
86
================
87
87
88
88
Given separate inputs for **year **, **month **, and **day **, will return a new instance. If any of these parameters
89
- are not provided, it will use the current value to fill it in . Accepts strings for the timezone and locale in the
89
+ are not provided, it will use the current year, month and day . Accepts strings for the timezone and locale in the
90
90
fourth and fifth parameters:
91
91
92
92
.. literalinclude :: time/008.php
93
93
94
94
createFromTime()
95
95
================
96
96
97
- Like ``createFromDate() `` except it is only concerned with the **hours **, **minutes **, and **seconds **. Uses the
97
+ Like ``createFromDate() ``, except it is only concerned with the **hours **, **minutes **, and **seconds **. Uses the
98
98
current day for the date portion of the Time instance. Accepts strings for the timezone and locale in the
99
99
fourth and fifth parameters:
100
100
@@ -104,7 +104,7 @@ create()
104
104
========
105
105
106
106
A combination of the previous two methods, takes **year **, **month **, **day **, **hour **, **minutes **, and **seconds **
107
- as separate parameters. Any value not provided will use the current date and time to determine . Accepts strings for the
107
+ as separate parameters. Any value not provided will use the current date and time. Accepts strings for the
108
108
timezone and locale in the fourth and fifth parameters:
109
109
110
110
.. literalinclude :: time/010.php
@@ -178,21 +178,21 @@ This will return a localized version of string formatted as (``Y-m-d H:i:s``):
178
178
toDateString()
179
179
==============
180
180
181
- Displays just the localized version of date portion of the Time:
181
+ Displays just the localized date portion of the Time:
182
182
183
183
.. literalinclude :: time/017.php
184
184
185
185
toTimeString()
186
186
==============
187
187
188
- Displays just the localized version of time portion of the value:
188
+ Displays just the localized time portion of the value:
189
189
190
190
.. literalinclude :: time/018.php
191
191
192
192
humanize()
193
193
==========
194
194
195
- This methods returns a string that displays the difference between the current date/time and the instance in a
195
+ This method returns a string that displays the difference between the current date/time and the instance in a
196
196
human readable format that is geared towards being easily understood. It can create strings like '3 hours ago',
197
197
'in 1 month', etc:
198
198
@@ -203,17 +203,18 @@ The exact time displayed is determined in the following manner:
203
203
=============================== =================================
204
204
Time difference Result
205
205
=============================== =================================
206
- $time > 1 year && < 2 years in 1 year / 1 year ago
207
- $time > 1 month && < 1 year in 6 months / 6 months ago
208
- $time > 7 days && < 1 month in 3 weeks / 3 weeks ago
209
- $time > today && < 7 days in 4 days / 4 days ago
210
- $time == tomorrow / yesterday Tomorrow / Yesterday
211
- $time > 59 minutes && < 1 day in 2 hours / 2 hours ago
212
- $time > now && < 1 hour in 35 minutes / 35 minutes ago
206
+ 1 year < $time < 2 years in 1 year / 1 year ago
207
+ 1 month < $time < 1 year in 6 months / 6 months ago
208
+ 7 days < $time < 1 month in 3 weeks / 3 weeks ago
209
+ today < $time < 7 days in 4 days / 4 days ago
210
+ $time == yesterday / tomorrow Yesterday / Tomorrow
211
+ 59 minutes < $time < 1 day in 2 hours / 2 hours ago
212
+ now < $time < 1 hour in 35 minutes / 35 minutes ago
213
213
$time == now Now
214
214
=============================== =================================
215
215
216
- The exact language used is controlled through the language file, **Time.php **.
216
+ The result strings are coming from the language file, **system/Language/en/Time.php **.
217
+ If you want to overwrite them, create **app/Language/{locale}/Time.php **.
217
218
218
219
******************************
219
220
Working with Individual Values
@@ -240,7 +241,7 @@ In addition to these, a number of methods exist to provide additional informatio
240
241
getAge()
241
242
--------
242
243
243
- Returns the age, in years, of between the Time's instance and the current time. Perfect for checking
244
+ Returns the age, in years, between the Time instance and the current time. Perfect for checking
244
245
the age of someone based on their birthday:
245
246
246
247
.. literalinclude :: time/022.php
@@ -402,7 +403,7 @@ humanize()
402
403
403
404
Much like Time's ``humanize() `` method, this returns a string that displays the difference between the times in a
404
405
human readable format that is geared towards being easily understood. It can create strings like '3 hours ago',
405
- 'in 1 month', etc. The biggest differences are in how very recent dates are handled:
406
+ 'in 1 month', etc. The biggest difference is in how very recent dates are handled:
406
407
407
408
.. literalinclude :: time/041.php
408
409
@@ -411,13 +412,14 @@ The exact time displayed is determined in the following manner:
411
412
=============================== =================================
412
413
Time difference Result
413
414
=============================== =================================
414
- $time > 1 year && < 2 years in 1 year / 1 year ago
415
- $time > 1 month && < 1 year in 6 months / 6 months ago
416
- $time > 7 days && < 1 month in 3 weeks / 3 weeks ago
417
- $time > today && < 7 days in 4 days / 4 days ago
418
- $time > 1 hour && < 1 day in 8 hours / 8 hours ago
419
- $time > 1 minute && < 1 hour in 35 minutes / 35 minutes ago
415
+ 1 year < $time < 2 years in 1 year / 1 year ago
416
+ 1 month < $time < 1 year in 6 months / 6 months ago
417
+ 7 days < $time < 1 month in 3 weeks / 3 weeks ago
418
+ today < $time < 7 days in 4 days / 4 days ago
419
+ 1 hour < $time < 1 day in 8 hours / 8 hours ago
420
+ 1 minute < $time < 1 hour in 35 minutes / 35 minutes ago
420
421
$time < 1 minute Now
421
422
=============================== =================================
422
423
423
- The exact language used is controlled through the language file, **Time.php **.
424
+ The result strings are coming from the language file, **system/Language/en/Time.php **.
425
+ If you want to overwrite them, create **app/Language/{locale}/Time.php **.
0 commit comments