Skip to content

Commit

Permalink
CakeTime migrated to Intl.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilwylegala committed May 30, 2024
1 parent 10b466c commit d68dc79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"source": "https://github.com/cakephp/cakephp"
},
"require": {
"php": "^8.0"
"php": "^8.0",
"ext-mbstring": "*",
"symfony/polyfill-intl-icu": "^1.29",
"php81_bc/strftime": "^0.7.5"
},
"suggest": {
"ext-openssl": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption",
Expand Down
22 changes: 11 additions & 11 deletions lib/Cake/Test/Case/Utility/CakeTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ public function testTimeAgoInWordsWithFormat() {
$this->assertEquals('on 2007-09-25', $result);

$result = $this->Time->timeAgoInWords('2007-9-25', '%x');
// @codingStandardsIgnoreStart
$this->assertEquals('on ' . @strftime('%x', strtotime('2007-9-25')), $result);
// @codingStandardsIgnoreEnd
$this->assertEquals('on ' . PHP81_BC\strftime('%x', strtotime('2007-9-25')), $result);

$result = $this->Time->timeAgoInWords(
strtotime('+2 weeks +2 days'),
Expand All @@ -306,7 +304,7 @@ public function testTimeAgoInWordsWithFormat() {
array('end' => '1 month', 'format' => '%x')
);
// @codingStandardsIgnoreStart
$this->assertEquals('on ' . @strftime('%x', strtotime('+2 months +2 days')), $result);
$this->assertEquals('on ' . PHP81_BC\strftime('%x', strtotime('+2 months +2 days')), $result);
// @codingStandardsIgnoreEnd
}

Expand Down Expand Up @@ -476,11 +474,11 @@ public function testNiceShort() {
* @return void
*/
public function testNiceShortI18n() {
$restore = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'es_ES');
$restore = Locale::getDefault();
Locale::setDefault('es_ES');
$time = strtotime('2015-01-07 03:05:00');
$this->assertEquals('ene 7th 2015, 03:05', $this->Time->niceShort($time));
setlocale(LC_ALL, $restore);
Locale::setDefault($restore);
}

/**
Expand Down Expand Up @@ -1166,20 +1164,22 @@ public function testConvertPercentE() {
* @return void
*/
public function testI18nFormat() {
$resetLocale = Locale::getDefault();
App::build(array(
'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
), App::RESET);
Configure::write('Config.language', 'time_test');

$time = strtotime('Thu Jan 14 13:59:28 2010');

Locale::setDefault('en_US');
$result = $this->Time->i18nFormat($time);
$expected = '14/01/10';
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, '%c');
// @codingStandardsIgnoreStart
$expected = 'jue 14 ene 2010 13:59:28 ' . mb_convert_encoding(@strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
$expected = 'jue 14 ene 2010 13:59:28 ' . mb_convert_encoding(PHP81_BC\strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
// @codingStandardsIgnoreEnd
$this->assertEquals($expected, $result);

Expand All @@ -1194,9 +1194,7 @@ public function testI18nFormat() {
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, '%c');
// @codingStandardsIgnoreStart
$expected = 'mié 13 ene 2010 13:59:28 ' . mb_convert_encoding(@strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
// @codingStandardsIgnoreEnd
$expected = 'mié 13 ene 2010 13:59:28 ' . mb_convert_encoding(PHP81_BC\strftime('%Z', $time), 'UTF-8', 'ISO-8859-1');
$this->assertEquals($expected, $result);

$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
Expand All @@ -1206,6 +1204,8 @@ public function testI18nFormat() {
$result = $this->Time->i18nFormat('invalid date', '%x', 'Date invalid');
$expected = 'Date invalid';
$this->assertEquals($expected, $result);

Locale::setDefault($resetLocale);
}

public function testI18nFormatTimezoneConversionToUTC() {
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Utility/CakeTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,8 @@ public static function listTimezones($filter = null, $country = null, $options =
* @return string formatted string with correct encoding.
*/
protected static function _strftime($format, $timestamp) {
// @codingStandardsIgnoreStart
$format = @strftime($format, $timestamp);
// @codingStandardsIgnoreEnd
$format = PHP81_BC\strftime($format, $timestamp);

$encoding = Configure::read('App.encoding');
if (!empty($encoding) && $encoding === 'UTF-8') {
if (function_exists('mb_check_encoding')) {
Expand Down

0 comments on commit d68dc79

Please sign in to comment.