original_string: public function edit_field_add($mform) {
          // Get the current calendar in use - see MDL-18375.
          $calendartype = \core_calendar\type_factory::get_calendar_instance();
  
          // Check if the field is required.
          if ($this->field->required) {
              $optional = false;
          } else {
              $optional = true;
          }
  
          // Convert the year stored in the DB as gregorian to that used by the calendar type.
          $startdate = $calendartype->convert_from_gregorian($this->field->param1, 1, 1);
          $stopdate = $calendartype->convert_from_gregorian($this->field->param2, 1, 1);
  
          $attributes = array(
              'startyear' => $startdate['year'],
              'stopyear'  => $stopdate['year'],
              'optional'  => $optional
          );
  
          // Check if they wanted to include time as well.
          if (!empty($this->field->param3)) {
              $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes);
          } else {
              $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes);
          }
  
          $mform->setType($this->inputname, PARAM_INT);
          $mform->setDefault($this->inputname, time());
      }
code: public function edit_field_add($mform) {
          // Get the current calendar in use - see MDL-18375.
          $calendartype = \core_calendar\type_factory::get_calendar_instance();
  
          // Check if the field is required.
          if ($this->field->required) {
              $optional = false;
          } else {
              $optional = true;
          }
  
          // Convert the year stored in the DB as gregorian to that used by the calendar type.
          $startdate = $calendartype->convert_from_gregorian($this->field->param1, 1, 1);
          $stopdate = $calendartype->convert_from_gregorian($this->field->param2, 1, 1);
  
          $attributes = array(
              'startyear' => $startdate['year'],
              'stopyear'  => $stopdate['year'],
              'optional'  => $optional
          );
  
          // Check if they wanted to include time as well.
          if (!empty($this->field->param3)) {
              $mform->addElement('date_time_selector', $this->inputname, format_string($this->field->name), $attributes);
          } else {
              $mform->addElement('date_selector', $this->inputname, format_string($this->field->name), $attributes);
          }
  
          $mform->setType($this->inputname, PARAM_INT);
          $mform->setDefault($this->inputname, time());
      }
code_tokens: public function edit_field_add ( $ mform ) { // Get the current calendar in use - see MDL-18375. $ calendartype = \ core_calendar \ type_factory :: get_calendar_instance ( ) ; // Check if the field is required. if ( $ this -> field -> required ) { $ optional = false ; } else { $ optional = true ; } // Convert the year stored in the DB as gregorian to that used by the calendar type. $ startdate = $ calendartype -> convert_from_gregorian ( $ this -> field -> param1 , 1 , 1 ) ; $ stopdate = $ calendartype -> convert_from_gregorian ( $ this -> field -> param2 , 1 , 1 ) ; $ attributes = array ( 'startyear' => $ startdate [ 'year' ] , 'stopyear' => $ stopdate [ 'year' ] , 'optional' => $ optional ) ; // Check if they wanted to include time as well. if ( ! empty ( $ this -> field -> param3 ) ) { $ mform -> addElement ( 'date_time_selector' , $ this -> inputname , format_string ( $ this -> field -> name ) , $ attributes ) ; } else { $ mform -> addElement ( 'date_selector' , $ this -> inputname , format_string ( $ this -> field -> name ) , $ attributes ) ; } $ mform -> setType ( $ this -> inputname , PARAM_INT ) ; $ mform -> setDefault ( $ this -> inputname , time ( ) ) ; }
docstring: Handles editing datetime fields.
  
  @param moodleform $mform
docstring_tokens: Handles editing datetime fields .