Skip to content

Commit

Permalink
MDl-38494 user: Fix uploaded datetime profile fields
Browse files Browse the repository at this point in the history
  • Loading branch information
PeloNZ authored and Rajesh Taneja committed Mar 25, 2013
1 parent 7112729 commit 7605dba
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions user/profile/field/datetime/field.class.php
Expand Up @@ -40,6 +40,31 @@ function edit_field_add($mform) {
$mform->setDefault($this->inputname, time());
}

/**
* If timestamp is in YYYY-MM-DD or YYYY-MM-DD-HH-MM-SS format, then convert it to timestamp.
*
* @param string|int $datetime datetime to be converted.
* @param stdClass $datarecord The object that will be used to save the record
* @return int timestamp
* @since Moodle 2.5
*/
function edit_save_data_preprocess($datetime, $datarecord) {
// If timestamp then explode it to check if year is within field limit.
$isstring = strpos($datetime, '-');
if (empty($isstring)) {
$datetime = date('Y-m-d-H-i-s', $datetime);
}

$datetime = explode('-', $datetime);
// Bound year with start and end year.
$datetime[0] = min(max($datetime[0], $this->field->param1), $this->field->param2);
if (!empty($this->field->param3) && count($datetime) == 6) {
return make_timestamp($datetime[0], $datetime[1], $datetime[2], $datetime[3], $datetime[4], $datetime[5]);
} else {
return make_timestamp($datetime[0], $datetime[1], $datetime[2]);
}
}

/**
* Display the data for this field
*/
Expand Down

0 comments on commit 7605dba

Please sign in to comment.