-
Bug
-
Resolution: Fixed
-
Major
-
1.9.17, 2.0.8, 2.1, 2.2
-
Moodle 2.2.2, Windows 7, XAMPP Apache, PHP
-
MOODLE_19_STABLE, MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
-
MOODLE_23_STABLE
-
w23_
MDL-32632_m23_windate -
Easy
-
This issue was reported long ago as MDL-13389 but it's closed and still unresolved so reporting again.
On every major version of Moodle running on Windows servers, userdate in moodlelib.php can return corrupted date string. The problem is that userdate is usually called with date format parameter defined in langconfig.php (encoded in UTF-8), passes it directly to strftime, then the result string is converted from Windows ANSI encoding to UTF-8.
The problem doesn't appear in most languages where format strings contain ASCII characters only.
en: $string['strftimedaydatetime'] = '%A, %d. %B %Y, %H:%M';
fr: $string['strftimedaydatetime'] = '%A %d %B %Y, %H:%M';
However, the locales of East Asian languages have non-ASCII characters in format strings. It's because they write year, month and day followed by words which mean year, month and day, rather than bare numbers.
ja: $string['strftimedaydatetime'] = '%Y年 %m月 %d日(%A) %H:%M';
zh: $string['strftimedaydatetime'] = '%Y年%m月%d日 %A %H:%M';
ko: $string['strftimedaydatetime'] = '%Y년 %B %d일, %A, %p %I:%M';
Currently userdate converts only the returned string from strftime, but it should also convert format parameter before passing it to strftime. Otherwise the final conversion is done on a mixture of local encoding and UTF-8. Userdate outputs corrupted string, or if it meets byte sequence that can't be converted, nothing is output where date should come.
Added a simple patch to solve this problem. It converts $format passed to the function as parameter or obtained inside the function before calling strftime. And instancing textlib is deprecated now so changed the calls to the convert function to static.
- duplicates
-
MDL-13389 function userdate() returns wrong string (mixed different character encoding) in multi-byte character encoding environment (ex. in Japanese)
-
- Closed
-
-
MDL-14149 day names, month names and am/pm appear garbled in Chinese and Japanese on Windows servers
-
- Closed
-
- is duplicated by
-
MDL-9901 No need convert dates to utf-8 on Windows at userdate()
-
- Closed
-
- will help resolve
-
MDL-33545 userdate() returns corrupted string on Windows environment (patch) (backport of MDL-32632)
-
- Closed
-