protected function validate_duedate($value) {

        // During update.
        if ($this->get('id')) {
            $before = $this->beforeupdate->get('duedate');

            // The value has not changed, then it's always OK.
            if ($before == $value) {
                return true;
            }
        }

        // During create and update, the date must be set in the future, or not set.
        if (!empty($value) && $value <= time() - 600) {
            // We cannot set the date in the past. But we allow for 10 minutes of margin so that
            // a user can set the due date to "now" without risking to hit a validation error.
            return new lang_string('errorcannotsetduedateinthepast', 'core_competency');
        }

        return true;
    }