Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Parser/Chan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Parser/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
5 changes: 5 additions & 0 deletions src/Parser/Indi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
97 changes: 97 additions & 0 deletions src/Record/Chan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -31,6 +39,11 @@ class Chan extends \Gedcom\Record
*/
protected $time;

/**
* @var string
*/
protected $datetime;

/**
* @var array
*/
Expand Down Expand Up @@ -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']);
}
}
39 changes: 35 additions & 4 deletions src/Record/Indi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

namespace Gedcom\Record;

use \Gedcom\Record;


/**
* Class Indi.
*/
Expand Down Expand Up @@ -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
*
Expand Down