MDL-52354 select_time: Make select_time respect the set calendar type
authorShamim Rezaie <support@foodle.org>
Tue, 1 Dec 2015 04:37:07 +0000 (15:37 +1100)
committerJun Pataleta <jun@moodle.com>
Thu, 17 Dec 2015 23:58:39 +0000 (17:58 -0600)
The select_time method updated to display form elements in accordance
to the calendar type plugin that is in use.

lib/moodlelib.php
lib/outputcomponents.php

index 55c8b69..c26d8c6 100644 (file)
@@ -2208,7 +2208,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
index 7e85830..b44b279 100644 (file)
@@ -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':