From e212341c33838c2d9b31f5c9353990b26a8d86f3 Mon Sep 17 00:00:00 2001 From: Heru Firmansyah Date: Wed, 25 Aug 2021 21:00:20 +0800 Subject: [PATCH 1/2] Fix fillable birthday, deathday, and burialday --- src/Parser/Date.php | 2 +- src/Parser/Indi.php | 5 +++++ src/Record/Indi.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Parser/Date.php b/src/Parser/Date.php index 1154905d..fb9f530c 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 ba44a748..3f520a06 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/Indi.php b/src/Record/Indi.php index 6e9d8c7b..5e801b19 100644 --- a/src/Record/Indi.php +++ b/src/Record/Indi.php @@ -141,6 +141,10 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable protected $birthday; + protected $deathday; + + protected $burialday; + public function setBirthday($birthday = '') { $this->birthday = $birthday; @@ -153,6 +157,30 @@ 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 * From adc6a02a8eddb165a2dc545749aad8e772bacbc7 Mon Sep 17 00:00:00 2001 From: Heru Firmansyah Date: Thu, 26 Aug 2021 00:20:36 +0800 Subject: [PATCH 2/2] Fix fillable nick, type, and chan --- src/Parser/Chan.php | 3 ++ src/Record/Chan.php | 97 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/Parser/Chan.php b/src/Parser/Chan.php index 741543ed..41fad341 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/Record/Chan.php b/src/Record/Chan.php index 89ac85de..5984b6dd 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']); + } }