Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilwylegala committed May 30, 2024
1 parent 2636fd3 commit 14de593
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions lib/Cake/Utility/CakeTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -1167,29 +1167,54 @@ public static function listTimezones($filter = null, $country = null, $options =
* @return string formatted string with correct encoding.
*/
protected static function _strftime($format, $timestamp) {
$intlFormat = self::convertStrftimeFormatToIntl($format);
$locale = setlocale(LC_ALL, 0);
$dateFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
date_default_timezone_get(),
IntlDateFormatter::GREGORIAN,
$format
$intlFormat
);
$format = $dateFormatter->format($timestamp);
$formatted = $dateFormatter->format($timestamp);

$encoding = Configure::read('App.encoding');
if (!empty($encoding) && $encoding === 'UTF-8') {
if (function_exists('mb_check_encoding')) {
$valid = mb_check_encoding($format, $encoding);
$valid = mb_check_encoding($formatted, $encoding);
} else {
$valid = Multibyte::checkMultibyte($format);
$valid = Multibyte::checkMultibyte($formatted);
}
if (!$valid) {
$format = mb_convert_encoding($format, 'UTF-8', 'ISO-8859-1');
$formatted = mb_convert_encoding($formatted, 'UTF-8', 'ISO-8859-1');
}
}
return $format;
return $formatted;
}

private static function convertStrftimeFormatToIntl($format) {
$conversion = array(
'%a' => 'eee', // abbreviated weekday name
'%A' => 'eeee', // full weekday name
'%w' => 'e', // day of the week
'%d' => 'dd', // day of the month
'%b' => 'MMM', // abbreviated month name
'%B' => 'MMMM', // full month name
'%m' => 'MM', // month of the year
'%y' => 'yy', // year without century
'%Y' => 'yyyy', // year with century
'%H' => 'HH', // hour (24-hour clock)
'%I' => 'hh', // hour (12-hour clock)
'%p' => 'a', // AM or PM designation
'%M' => 'mm', // minute
'%S' => 'ss', // second
'%z' => 'ZZZZ', // time zone offset
'%Z' => 'zzzz', // time zone abbreviation
'%%' => '%' // literal percentage sign
);

return strtr($format, $conversion);
}

/**
Expand Down

0 comments on commit 14de593

Please sign in to comment.