MDL-37780 hack around some unicode date formatting issues on Windows
This commit is contained in:
+2
-4
@@ -2140,8 +2140,7 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour
|
||||
function date_format_string($date, $format, $tz = 99) {
|
||||
global $CFG;
|
||||
if (abs($tz) > 13) {
|
||||
if ($CFG->ostype == 'WINDOWS') {
|
||||
$localewincharset = get_string('localewincharset', 'langconfig');
|
||||
if ($CFG->ostype == 'WINDOWS' and $localewincharset = get_string('localewincharset', 'langconfig')) {
|
||||
$format = textlib::convert($format, 'utf-8', $localewincharset);
|
||||
$datestring = strftime($format, $date);
|
||||
$datestring = textlib::convert($datestring, $localewincharset, 'utf-8');
|
||||
@@ -2149,8 +2148,7 @@ function date_format_string($date, $format, $tz = 99) {
|
||||
$datestring = strftime($format, $date);
|
||||
}
|
||||
} else {
|
||||
if ($CFG->ostype == 'WINDOWS') {
|
||||
$localewincharset = get_string('localewincharset', 'langconfig');
|
||||
if ($CFG->ostype == 'WINDOWS' and $localewincharset = get_string('localewincharset', 'langconfig')) {
|
||||
$format = textlib::convert($format, 'utf-8', $localewincharset);
|
||||
$datestring = gmstrftime($format, $date);
|
||||
$datestring = textlib::convert($datestring, $localewincharset, 'utf-8');
|
||||
|
||||
@@ -2131,9 +2131,15 @@ class moodlelib_testcase extends advanced_testcase {
|
||||
* Test the function date_format_string().
|
||||
*/
|
||||
function test_date_format_string() {
|
||||
global $CFG;
|
||||
|
||||
// Forcing locale and timezone.
|
||||
$oldlocale = setlocale(LC_TIME, '0');
|
||||
setlocale(LC_TIME, 'en_AU.UTF-8');
|
||||
if ($CFG->ostype == 'WINDOWS') {
|
||||
setlocale(LC_TIME, 'English_Australia.1252');
|
||||
} else {
|
||||
setlocale(LC_TIME, 'en_AU.UTF-8');
|
||||
}
|
||||
$systemdefaulttimezone = date_default_timezone_get();
|
||||
date_default_timezone_set('Australia/Perth');
|
||||
|
||||
@@ -2153,6 +2159,10 @@ class moodlelib_testcase extends advanced_testcase {
|
||||
'str' => '%A, %d %B %Y, %I:%M %p',
|
||||
'expected' => 'Saturday, 01 January 2011, 10:00 AM'
|
||||
),
|
||||
// Following tests pass on Windows only because en lang pack does
|
||||
// not contain localewincharset, in real life lang pack maintainers
|
||||
// may use only characters that are present in localewincharset
|
||||
// in format strings!
|
||||
array(
|
||||
'tz' => 99,
|
||||
'str' => 'Žluťoučký koníček %A',
|
||||
|
||||
Reference in New Issue
Block a user