Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Showing with 25 additions and 0 deletions.
  1. +25 −0 user/profile/field/datetime/field.class.php
View
25 user/profile/field/datetime/field.class.php
@@ -41,6 +41,31 @@ function edit_field_add($mform) {
}
/**
+ * 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
*/
function display_data() {
Please sign in to comment.
Something went wrong with that request. Please try again.