protected function validate_duedate($value) {

        // We do not check duedate when plan is draft, complete, unset, or based on a template.
        if ($this->is_based_on_template()
                || $this->is_draft()
                || $this->get('status') == self::STATUS_COMPLETE
                || empty($value)) {
            return true;
        }

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

            // The value has not changed, then it's always OK. Though if we're going
            // from draft to active it has to has to be validated.
            if ($before == $value && !in_array($beforestatus, self::get_draft_statuses())) {
                return true;
            }
        }

        if ($value <= time()) {
            // We cannot set the date in the past.
            return new lang_string('errorcannotsetduedateinthepast', 'core_competency');
        }

        if ($value <= time() + self::DUEDATE_THRESHOLD) {
            // We cannot set the date too soon, but we can leave it empty.
            return new lang_string('errorcannotsetduedatetoosoon', 'core_competency');
        }

        return true;
    }