original_string: public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) {
          global $OUTPUT;
  
          if (!$currenttime) {
              $currenttime = time();
          }
          $calendartype = \core_calendar\type_factory::get_calendar_instance();
          $currentdate = $calendartype->timestamp_to_date_array($currenttime);
          $userdatetype = $type;
          $timeunits = array();
  
          switch ($type) {
              case 'years':
                  $timeunits = $calendartype->get_years();
                  $userdatetype = 'year';
                  break;
              case 'months':
                  $timeunits = $calendartype->get_months();
                  $userdatetype = 'month';
                  $currentdate['month'] = (int)$currentdate['mon'];
                  break;
              case 'days':
                  $timeunits = $calendartype->get_days();
                  $userdatetype = 'mday';
                  break;
              case 'hours':
                  for ($i=0; $i<=23; $i++) {
                      $timeunits[$i] = sprintf("%02d",$i);
                  }
                  break;
              case 'minutes':
                  if ($step != 1) {
                      $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
                  }
  
                  for ($i=0; $i<=59; $i+=$step) {
                      $timeunits[$i] = sprintf("%02d",$i);
                  }
                  break;
              default:
                  throw new coding_exception("Time type $type is not supported by html_writer::select_time().");
          }
  
          $attributes = (array) $attributes;
          $data = (object) [
              'name' => $name,
              'id' => !empty($attributes['id']) ? $attributes['id'] : self::random_id('ts_'),
              'label' => get_string(substr($type, 0, -1), 'form'),
              'options' => array_map(function($value) use ($timeunits, $currentdate, $userdatetype) {
                  return [
                      'name' => $timeunits[$value],
                      'value' => $value,
                      'selected' => $currentdate[$userdatetype] == $value
                  ];
              }, array_keys($timeunits)),
          ];
  
          unset($attributes['id']);
          unset($attributes['name']);
          $data->attributes = array_map(function($name) use ($attributes) {
              return [
                  'name' => $name,
                  'value' => $attributes[$name]
              ];
          }, array_keys($attributes));
  
          return $OUTPUT->render_from_template('core/select_time', $data);
      }
code: public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) {
          global $OUTPUT;
  
          if (!$currenttime) {
              $currenttime = time();
          }
          $calendartype = \core_calendar\type_factory::get_calendar_instance();
          $currentdate = $calendartype->timestamp_to_date_array($currenttime);
          $userdatetype = $type;
          $timeunits = array();
  
          switch ($type) {
              case 'years':
                  $timeunits = $calendartype->get_years();
                  $userdatetype = 'year';
                  break;
              case 'months':
                  $timeunits = $calendartype->get_months();
                  $userdatetype = 'month';
                  $currentdate['month'] = (int)$currentdate['mon'];
                  break;
              case 'days':
                  $timeunits = $calendartype->get_days();
                  $userdatetype = 'mday';
                  break;
              case 'hours':
                  for ($i=0; $i<=23; $i++) {
                      $timeunits[$i] = sprintf("%02d",$i);
                  }
                  break;
              case 'minutes':
                  if ($step != 1) {
                      $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
                  }
  
                  for ($i=0; $i<=59; $i+=$step) {
                      $timeunits[$i] = sprintf("%02d",$i);
                  }
                  break;
              default:
                  throw new coding_exception("Time type $type is not supported by html_writer::select_time().");
          }
  
          $attributes = (array) $attributes;
          $data = (object) [
              'name' => $name,
              'id' => !empty($attributes['id']) ? $attributes['id'] : self::random_id('ts_'),
              'label' => get_string(substr($type, 0, -1), 'form'),
              'options' => array_map(function($value) use ($timeunits, $currentdate, $userdatetype) {
                  return [
                      'name' => $timeunits[$value],
                      'value' => $value,
                      'selected' => $currentdate[$userdatetype] == $value
                  ];
              }, array_keys($timeunits)),
          ];
  
          unset($attributes['id']);
          unset($attributes['name']);
          $data->attributes = array_map(function($name) use ($attributes) {
              return [
                  'name' => $name,
                  'value' => $attributes[$name]
              ];
          }, array_keys($attributes));
  
          return $OUTPUT->render_from_template('core/select_time', $data);
      }
code_tokens: public static function select_time ( $ type , $ name , $ currenttime = 0 , $ step = 5 , array $ attributes = null ) { global $ OUTPUT ; if ( ! $ currenttime ) { $ currenttime = time ( ) ; } $ calendartype = \ core_calendar \ type_factory :: get_calendar_instance ( ) ; $ currentdate = $ calendartype -> timestamp_to_date_array ( $ currenttime ) ; $ userdatetype = $ type ; $ timeunits = array ( ) ; switch ( $ type ) { case 'years' : $ timeunits = $ calendartype -> get_years ( ) ; $ userdatetype = 'year' ; break ; case 'months' : $ timeunits = $ calendartype -> get_months ( ) ; $ userdatetype = 'month' ; $ currentdate [ 'month' ] = ( int ) $ currentdate [ 'mon' ] ; break ; case 'days' : $ timeunits = $ calendartype -> get_days ( ) ; $ userdatetype = 'mday' ; break ; case 'hours' : for ( $ i = 0 ; $ i <= 23 ; $ i ++ ) { $ timeunits [ $ i ] = sprintf ( "%02d" , $ i ) ; } break ; case 'minutes' : if ( $ step != 1 ) { $ currentdate [ 'minutes' ] = ceil ( $ currentdate [ 'minutes' ] / $ step ) * $ step ; } for ( $ i = 0 ; $ i <= 59 ; $ i += $ step ) { $ timeunits [ $ i ] = sprintf ( "%02d" , $ i ) ; } break ; default : throw new coding_exception ( "Time type $type is not supported by html_writer::select_time()." ) ; } $ attributes = ( array ) $ attributes ; $ data = ( object ) [ 'name' => $ name , 'id' => ! empty ( $ attributes [ 'id' ] ) ? $ attributes [ 'id' ] : self :: random_id ( 'ts_' ) , 'label' => get_string ( substr ( $ type , 0 , - 1 ) , 'form' ) , 'options' => array_map ( function ( $ value ) use ( $ timeunits , $ currentdate , $ userdatetype ) { return [ 'name' => $ timeunits [ $ value ] , 'value' => $ value , 'selected' => $ currentdate [ $ userdatetype ] == $ value ] ; } , array_keys ( $ timeunits ) ) , ] ; unset ( $ attributes [ 'id' ] ) ; unset ( $ attributes [ 'name' ] ) ; $ data -> attributes = array_map ( function ( $ name ) use ( $ attributes ) { return [ 'name' => $ name , 'value' => $ attributes [ $ name ] ] ; } , array_keys ( $ attributes ) ) ; return $ OUTPUT -> render_from_template ( 'core/select_time' , $ data ) ; }
docstring: This is a shortcut for making an hour selector menu.
  
  @param string $type The type of selector (years, months, days, hours, minutes)
  @param string $name fieldname
  @param int $currenttime A default timestamp in GMT
  @param int $step minute spacing
  @param array $attributes - html select element attributes
  @return HTML fragment
docstring_tokens: This is a shortcut for making an hour selector menu .