From 0f64a45eafc09d6c00344f2dab8b311dbb123ddf Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Tue, 1 Dec 2015 15:37:07 +1100 Subject: [PATCH 1/2] MDL-52354 select_time: Make select_time respect the set calendar type The select_time method updated to display form elements in accordance to the calendar type plugin that is in use. --- lib/moodlelib.php | 2 +- lib/outputcomponents.php | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 145952f36fc..e6f8004b99a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2211,7 +2211,7 @@ function date_format_string($date, $format, $tz = 99) { /** * Given a $time timestamp in GMT (seconds since epoch), - * returns an array that represents the date in user time + * returns an array that represents the Gregorian date in user time * * @package core * @category time diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 7e858301ca7..b44b2796fc6 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1386,28 +1386,23 @@ class html_writer { if (!$currenttime) { $currenttime = time(); } - $currentdate = usergetdate($currenttime); + $calendartype = \core_calendar\type_factory::get_calendar_instance(); + $currentdate = $calendartype->timestamp_to_date_array($currenttime); $userdatetype = $type; $timeunits = array(); switch ($type) { case 'years': - for ($i=1970; $i<=2020; $i++) { - $timeunits[$i] = $i; - } + $timeunits = $calendartype->get_years(); $userdatetype = 'year'; break; case 'months': - for ($i=1; $i<=12; $i++) { - $timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B"); - } + $timeunits = $calendartype->get_months(); $userdatetype = 'month'; $currentdate['month'] = (int)$currentdate['mon']; break; case 'days': - for ($i=1; $i<=31; $i++) { - $timeunits[$i] = $i; - } + $timeunits = $calendartype->get_days(); $userdatetype = 'mday'; break; case 'hours': From 8ec0823dfedb9d3c5ad42b20660f2fde137da8c0 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 3 Dec 2015 17:58:21 +1100 Subject: [PATCH 2/2] MDL-52380 mod_forum: Non-Gregorian dates in forum advance search Convert the fromdate and todate date parts to Gregorian before passing them to make_timestamp --- lib/moodlelib.php | 2 +- mod/forum/search.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index e6f8004b99a..a6b9018d290 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2029,7 +2029,7 @@ function get_user_preferences($name = null, $default = null, $user = null) { // FUNCTIONS FOR HANDLING TIME. /** - * Given date parts in user time produce a GMT timestamp. + * Given Gregorian date parts in user time produce a GMT timestamp. * * @package core * @category time diff --git a/mod/forum/search.php b/mod/forum/search.php index 7784eb0daad..046ffa68451 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -46,7 +46,9 @@ $fromyear = optional_param('fromyear', 0, PARAM_INT); // Starting date $fromhour = optional_param('fromhour', 0, PARAM_INT); // Starting date $fromminute = optional_param('fromminute', 0, PARAM_INT); // Starting date if ($timefromrestrict) { - $datefrom = make_timestamp($fromyear, $frommonth, $fromday, $fromhour, $fromminute); + $calendartype = \core_calendar\type_factory::get_calendar_instance(); + $gregorianfrom = $calendartype->convert_to_gregorian($fromyear, $frommonth, $fromday); + $datefrom = make_timestamp($gregorianfrom['year'], $gregorianfrom['month'], $gregorianfrom['day'], $fromhour, $fromminute); } else { $datefrom = optional_param('datefrom', 0, PARAM_INT); // Starting date } @@ -58,7 +60,9 @@ $toyear = optional_param('toyear', 0, PARAM_INT); // Ending date $tohour = optional_param('tohour', 0, PARAM_INT); // Ending date $tominute = optional_param('tominute', 0, PARAM_INT); // Ending date if ($timetorestrict) { - $dateto = make_timestamp($toyear, $tomonth, $today, $tohour, $tominute); + $calendartype = \core_calendar\type_factory::get_calendar_instance(); + $gregorianto = $calendartype->convert_to_gregorian($toyear, $tomonth, $today); + $dateto = make_timestamp($gregorianto['year'], $gregorianto['month'], $gregorianto['day'], $tohour, $tominute); } else { $dateto = optional_param('dateto', 0, PARAM_INT); // Ending date }