Skip to content

Commit

Permalink
MDL-52354 select_time: Make select_time respect the set calendar type
Browse files Browse the repository at this point in the history
The select_time method updated to display form elements in accordance
to the calendar type plugin that is in use.
  • Loading branch information
rezaies authored and junpataleta committed Dec 17, 2015
1 parent 0dfcc25 commit 40a6393
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -1386,28 +1386,23 @@ public static function select_time($type, $name, $currenttime = 0, $step = 5, ar
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':
Expand Down

0 comments on commit 40a6393

Please sign in to comment.