diff --git a/src/Parser/Chan.php b/src/Parser/Chan.php index 4f355a17..ffefe485 100644 --- a/src/Parser/Chan.php +++ b/src/Parser/Chan.php @@ -55,6 +55,9 @@ public static function parse(\Gedcom\Parser $parser) $parser->forward(); } + $date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay() ; + $chan->setDatetime($date); + return $chan; } } diff --git a/src/Parser/Date.php b/src/Parser/Date.php index df8ef1f7..8dfacb49 100644 --- a/src/Parser/Date.php +++ b/src/Parser/Date.php @@ -39,6 +39,6 @@ public static function parse(\Gedcom\Parser $parser) return $dat->getYear().'-'.substr("0{$dat->getMonth()}", -2).'-'.substr("0{$dat->getDay()}", -2); } - return null; + return $dat->getYear(); } } diff --git a/src/Parser/Indi.php b/src/Parser/Indi.php index 7d079e03..e9ed8784 100644 --- a/src/Parser/Indi.php +++ b/src/Parser/Indi.php @@ -69,12 +69,17 @@ public static function parse(\Gedcom\Parser $parser) case 'BASM': case 'BLES': case 'BURI': + $burialday = \Gedcom\Parser\Date::parse($parser); + $indi->setBurialday($burialday); + break; case 'CENS': case 'CHR': case 'CHRA': case 'CONF': case 'CREM': case 'DEAT': + $deathday = \Gedcom\Parser\Date::parse($parser); + $indi->setDeathday($deathday); break; case 'EMIG': case 'FCOM': diff --git a/src/Record/Chan.php b/src/Record/Chan.php index 1d6a3542..cad77e39 100644 --- a/src/Record/Chan.php +++ b/src/Record/Chan.php @@ -21,6 +21,14 @@ */ class Chan extends \Gedcom\Record { + /** + * @var array + */ + private $months = [ + 'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06', + 'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12', + ]; + /** * @var string */ @@ -31,6 +39,11 @@ class Chan extends \Gedcom\Record */ protected $time; + /** + * @var string + */ + protected $datetime; + /** * @var array */ @@ -95,4 +108,88 @@ public function getTime() { return $this->time; } + + public function setDatetime($date) + { + $this->datetime = $date .' '. $this->time; + + return $this; + } + + public function getDatetime() + { + return $this->datetime; + } + + public function getMonth() + { + $record = explode(' ', $this->date); + if (count($record) > 0) { + if ($this->isPrefix($record[0])) { + unset($record[0]); + } + foreach ($record as $part) { + if (isset($this->months[trim($part)])) { + return $this->months[trim($part)]; + } + } + } + + return null; + } + + /** + * Return year part of date. + * + * @return int|null + */ + public function getYear() + { + $record = explode(' ', $this->date); + if (count($record) > 0) { + if ($this->isPrefix($record[0])) { + unset($record[0]); + } + if (count($record) > 0) { + return (int) end($record); + } + } + + return null; + } + + /** + * Return day part of date. + * + * @return int|null + */ + public function getDay() + { + $record = explode(' ', $this->date); + if (!empty($record[0])) { + if ($this->isPrefix($record[0])) { + unset($record[0]); + } + if (count($record) > 0) { + $day = (int) reset($record); + if ($day >= 1 && $day <= 31) { + return substr("0{$day}", -2); + } + } + } + + return null; + } + + /** + * Check if the first part is a prefix (eg 'BEF', 'ABT',). + * + * @param string $datePart Date part to be checked + * + * @return bool + */ + private function isPrefix($datePart) + { + return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']); + } } diff --git a/src/Record/Indi.php b/src/Record/Indi.php index a4f36946..5e801b19 100644 --- a/src/Record/Indi.php +++ b/src/Record/Indi.php @@ -14,6 +14,9 @@ namespace Gedcom\Record; +use \Gedcom\Record; + + /** * Class Indi. */ @@ -135,21 +138,49 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable * @var Indi\Asso[] */ protected $asso = []; - + protected $birthday; - + + protected $deathday; + + protected $burialday; + public function setBirthday($birthday = '') { $this->birthday = $birthday; - + return $this; } - + public function getBirthday() { return $this->birthday; } + public function setDeathday($deathday = '') + { + $this->deathday = $deathday; + + return $this; + } + + public function getDeathday() + { + return $this->deathday; + } + + public function setBurialday($burialday = '') + { + $this->burialday = $burialday; + + return $this; + } + + public function getBurialday() + { + return $this->burialday; + } + /** * @param string $id *