Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-32632

userdate() returns corrupted string on Windows environment (patch)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.3
    • 1.9.17, 2.0.8, 2.1, 2.2
    • General, Language
    • 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
    • Hide

      1/ install cs and ja lang packs on windows test server
      2/ find a page that shows localised data (list of discussions for example)
      3/ switch to Czech and Japanese and verify there are valid unicode chars displayed in dates

      Show
      1/ install cs and ja lang packs on windows test server 2/ find a page that shows localised data (list of discussions for example) 3/ switch to Czech and Japanese and verify there are valid unicode chars displayed in dates

      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.

            skodak Petr Skoda
            k-yama Koichi Yamashita
            Dan Poltawski Dan Poltawski
            Dan Poltawski Dan Poltawski
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.