From 7827edc78d167bcc055930c8f890e60116905ac3 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 23 Dec 2022 00:01:26 +0100 Subject: [PATCH 1/2] MDL-76537 core: Fix date_format_string() to work with php-intl With Moodle 4.1 and up, we have stopped to work with strftime(), because it's deprecated for PHP 8.1 and up and, instead we are using core_date::strftime() that performs the conversions using the php-intl extension. The original strftime() had a lot of OS-specific dependencies, both about locale names and charsets used to provide the information. Instead, the php-intl gets rid of all those OS-specific nightmares and only uses ICU/Unicode locales and UTF-8. Because of that, the old utf-8 => windows charset => utf-8 conversions aren't needed anymore. Hence, removing them. --- lib/moodlelib.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 3167387ade9..6f8556b89d8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2362,18 +2362,6 @@ function userdate_htmltime($date, $format = '', $timezone = 99, $fixday = true, * @since Moodle 2.3.3 */ function date_format_string($date, $format, $tz = 99) { - global $CFG; - - $localewincharset = null; - // Get the calendar type user is using. - if ($CFG->ostype == 'WINDOWS') { - $calendartype = \core_calendar\type_factory::get_calendar_instance(); - $localewincharset = $calendartype->locale_win_charset(); - } - - if ($localewincharset) { - $format = core_text::convert($format, 'utf-8', $localewincharset); - } date_default_timezone_set(core_date::get_user_timezone($tz)); @@ -2391,10 +2379,6 @@ function date_format_string($date, $format, $tz = 99) { $datestring = core_date::strftime($format, $date); core_date::set_default_server_timezone(); - if ($localewincharset) { - $datestring = core_text::convert($datestring, $localewincharset, 'utf-8'); - } - return $datestring; } From 357f784091c0cd09afcc474c44ef001a2eed12f6 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 23 Dec 2022 18:18:16 +0100 Subject: [PATCH 2/2] MDL-76537 behat: Month and day names are lang-dependent correct utf-8 Just verify that calendars are always displayed with correct UTF-8 and in the language the user is currently using. --- calendar/tests/behat/calendar_utf8.feature | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 calendar/tests/behat/calendar_utf8.feature diff --git a/calendar/tests/behat/calendar_utf8.feature b/calendar/tests/behat/calendar_utf8.feature new file mode 100644 index 00000000000..bcb8fe0cf15 --- /dev/null +++ b/calendar/tests/behat/calendar_utf8.feature @@ -0,0 +1,29 @@ +@core @core_calendar +Feature: Verify that the day and month names are displayed using UTF-8 + In order to be able to use the calendar using different languages + As a user + I need to see the day and month names displayed properly + + Background: + Given remote langimport tests are enabled + + Scenario Outline: View the calendar for December 2012 with correct UTF-8 + Given I log in as "admin" + And I navigate to "Language > Language packs" in site administration + And I set the field "Available language packs" to "" + And I press "Install selected language pack(s)" + And I should see "Language pack '' was successfully installed" + And I follow "Preferences" in the user menu + And I follow "Preferred language" + And I set the field "Preferred language" to "" + And I press "Save changes" + When I view the calendar for "12" "2022" + Then I should see "" + And I should see "" + + Examples: + | lang | month | day | + | en_ar | December | Sat | + | es | diciembre | Sáb | + | fr | décembre | Sa | + | ru | декабря | Сб |