diff --git a/calendar/classes/type_base.php b/calendar/classes/type_base.php index 73671197c8e..a7d52fe2f57 100644 --- a/calendar/classes/type_base.php +++ b/calendar/classes/type_base.php @@ -210,4 +210,11 @@ abstract class type_base { * @return array the converted date */ public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0); + + /** + * This return locale for windows os. + * + * @return string locale + */ + public abstract function locale_win_charset(); } diff --git a/calendar/tests/calendartype_test_example.php b/calendar/tests/calendartype_test_example.php index e596edf717e..ab725d1d035 100644 --- a/calendar/tests/calendartype_test_example.php +++ b/calendar/tests/calendartype_test_example.php @@ -305,4 +305,13 @@ class structure extends type_base { 'hour' => (int) $hour, 'minute' => (int) $minute); } + + /** + * This return locale for windows os. + * + * @return string locale + */ + public function locale_win_charset() { + return get_string('localewincharset', 'langconfig'); + } } diff --git a/calendar/type/gregorian/classes/structure.php b/calendar/type/gregorian/classes/structure.php index 0c9ee7d4bde..950d8597533 100644 --- a/calendar/type/gregorian/classes/structure.php +++ b/calendar/type/gregorian/classes/structure.php @@ -418,4 +418,13 @@ class structure extends type_base { return $date; } + + /** + * This return locale for windows os. + * + * @return string locale + */ + public function locale_win_charset() { + return get_string('localewincharset', 'langconfig'); + } } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 2cf904a3888..c4111947fe5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2187,8 +2187,16 @@ function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour */ 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 (abs($tz) > 13) { - if ($CFG->ostype == 'WINDOWS' and $localewincharset = get_string('localewincharset', 'langconfig')) { + if ($localewincharset) { $format = core_text::convert($format, 'utf-8', $localewincharset); $datestring = strftime($format, $date); $datestring = core_text::convert($datestring, $localewincharset, 'utf-8'); @@ -2196,7 +2204,7 @@ function date_format_string($date, $format, $tz = 99) { $datestring = strftime($format, $date); } } else { - if ($CFG->ostype == 'WINDOWS' and $localewincharset = get_string('localewincharset', 'langconfig')) { + if ($localewincharset) { $format = core_text::convert($format, 'utf-8', $localewincharset); $datestring = gmstrftime($format, $date); $datestring = core_text::convert($datestring, $localewincharset, 'utf-8'); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index eff9dab4535..e683953c47c 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -52,6 +52,8 @@ information provided here is intended especially for developers. * New class introduced to help auto generate zIndex values for modal dialogues. Class "moodle-has-zindex" should set on any element which uses a non-default zindex and needs to ensure it doesn't show above a dialogue. +* Date format locale charset for windows server will come from calendar type and for gregorian it will use + lang file. DEPRECATIONS: Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices