/** * Tell whether the current state of the date is valid for a GedcomX formal date. * In particular, make sure it follows one of the following patterns: * [A]simpleDate * [A]simpleDate/[simpleDate|Duration] * [A]/simpleDate * R[repetitions]/simpleDate/(simpleDate|Duration) * @return bool */ public function isValid() { if ($this->isRecurring) { return !$this->isApproximate && $this->start !== null && $this->start->isValid() && ($this->end !== null && $this->end->isValid() || $this->end === null && $this->duration !== null && $this->duration->isValid()); } else { if ($this->numRepetitions !== null) { return false; } if ($this->start !== null && !$this->isRange) { return $this->end === null && $this->duration === null && $this->start->isValid(); } if ($this->isRange) { if ($this->start === null) { return $this->end !== null && $this->end->isValid() && $this->duration === null; } else { return ($this->end === null || $this->duration === null) && ($this->end === null || $this->end->isValid()) && ($this->duration === null || $this->duration->isValid()); } } } return false; }