File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1005,7 +1005,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
10051005 */
10061006 public function humanize ()
10071007 {
1008- $ now = IntlCalendar::fromDateTime (self ::now ($ this ->timezone )-> toDateTimeString () );
1008+ $ now = IntlCalendar::fromDateTime (self ::now ($ this ->timezone ));
10091009 $ time = $ this ->getCalendar ()->getTime ();
10101010
10111011 $ years = $ now ->fieldDifference ($ time , IntlCalendar::FIELD_YEAR );
@@ -1106,7 +1106,7 @@ public function getUTCObject($time, ?string $timezone = null)
11061106 */
11071107 public function getCalendar ()
11081108 {
1109- return IntlCalendar::fromDateTime ($ this -> toDateTimeString () );
1109+ return IntlCalendar::fromDateTime ($ this );
11101110 }
11111111
11121112 /**
Original file line number Diff line number Diff line change 1111
1212namespace CodeIgniter \I18n ;
1313
14+ use CodeIgniter \Config \Factories ;
1415use CodeIgniter \I18n \Exceptions \I18nException ;
1516use CodeIgniter \Test \CIUnitTestCase ;
17+ use Config \App ;
1618use DateTime ;
1719use DateTimeZone ;
1820use IntlDateFormatter ;
@@ -1025,6 +1027,31 @@ public function testHumanizeNow()
10251027 $ this ->assertSame ('Just now ' , $ time ->humanize ());
10261028 }
10271029
1030+ /**
1031+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/4708
1032+ */
1033+ public function testHumanizeWithArLocale ()
1034+ {
1035+ $ this ->resetServices ();
1036+
1037+ $ currentLocale = Locale::getDefault ();
1038+ Locale::setDefault ('ar ' );
1039+
1040+ $ config = new App ();
1041+ $ config ->supportedLocales = ['ar ' ];
1042+ $ config ->defaultLocale = 'ar ' ;
1043+ Factories::injectMock ('config ' , 'App ' , $ config );
1044+
1045+ Time::setTestNow ('2022-06-14 12:00 ' , 'America/Chicago ' );
1046+
1047+ $ date = '2022-06-07 12:00 ' ;
1048+ $ time = Time::parse ($ date , 'America/Chicago ' );
1049+
1050+ $ this ->assertSame ('١ week ago ' , $ time ->humanize ());
1051+
1052+ Locale::setDefault ($ currentLocale );
1053+ }
1054+
10281055 public function testSetTimezoneDate ()
10291056 {
10301057 $ time = Time::parse ('13 May 2020 10:00 ' , 'GMT ' );
You can’t perform that action at this time.
0 commit comments