Skip to content

Commit a7be7ed

Browse files
Merge pull request #28 from familytree365/fix/gedcom_import_export
Fix/gedcom import export
2 parents 82be039 + efd76b9 commit a7be7ed

5 files changed

Lines changed: 141 additions & 5 deletions

File tree

src/Parser/Chan.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public static function parse(\Gedcom\Parser $parser)
5555
$parser->forward();
5656
}
5757

58+
$date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay() ;
59+
$chan->setDatetime($date);
60+
5861
return $chan;
5962
}
6063
}

src/Parser/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public static function parse(\Gedcom\Parser $parser)
3939
return $dat->getYear().'-'.substr("0{$dat->getMonth()}", -2).'-'.substr("0{$dat->getDay()}", -2);
4040
}
4141

42-
return null;
42+
return $dat->getYear();
4343
}
4444
}

src/Parser/Indi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ public static function parse(\Gedcom\Parser $parser)
6969
case 'BASM':
7070
case 'BLES':
7171
case 'BURI':
72+
$burialday = \Gedcom\Parser\Date::parse($parser);
73+
$indi->setBurialday($burialday);
74+
break;
7275
case 'CENS':
7376
case 'CHR':
7477
case 'CHRA':
7578
case 'CONF':
7679
case 'CREM':
7780
case 'DEAT':
81+
$deathday = \Gedcom\Parser\Date::parse($parser);
82+
$indi->setDeathday($deathday);
7883
break;
7984
case 'EMIG':
8085
case 'FCOM':

src/Record/Chan.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
*/
2222
class Chan extends \Gedcom\Record
2323
{
24+
/**
25+
* @var array
26+
*/
27+
private $months = [
28+
'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06',
29+
'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12',
30+
];
31+
2432
/**
2533
* @var string
2634
*/
@@ -31,6 +39,11 @@ class Chan extends \Gedcom\Record
3139
*/
3240
protected $time;
3341

42+
/**
43+
* @var string
44+
*/
45+
protected $datetime;
46+
3447
/**
3548
* @var array
3649
*/
@@ -95,4 +108,88 @@ public function getTime()
95108
{
96109
return $this->time;
97110
}
111+
112+
public function setDatetime($date)
113+
{
114+
$this->datetime = $date .' '. $this->time;
115+
116+
return $this;
117+
}
118+
119+
public function getDatetime()
120+
{
121+
return $this->datetime;
122+
}
123+
124+
public function getMonth()
125+
{
126+
$record = explode(' ', $this->date);
127+
if (count($record) > 0) {
128+
if ($this->isPrefix($record[0])) {
129+
unset($record[0]);
130+
}
131+
foreach ($record as $part) {
132+
if (isset($this->months[trim($part)])) {
133+
return $this->months[trim($part)];
134+
}
135+
}
136+
}
137+
138+
return null;
139+
}
140+
141+
/**
142+
* Return year part of date.
143+
*
144+
* @return int|null
145+
*/
146+
public function getYear()
147+
{
148+
$record = explode(' ', $this->date);
149+
if (count($record) > 0) {
150+
if ($this->isPrefix($record[0])) {
151+
unset($record[0]);
152+
}
153+
if (count($record) > 0) {
154+
return (int) end($record);
155+
}
156+
}
157+
158+
return null;
159+
}
160+
161+
/**
162+
* Return day part of date.
163+
*
164+
* @return int|null
165+
*/
166+
public function getDay()
167+
{
168+
$record = explode(' ', $this->date);
169+
if (!empty($record[0])) {
170+
if ($this->isPrefix($record[0])) {
171+
unset($record[0]);
172+
}
173+
if (count($record) > 0) {
174+
$day = (int) reset($record);
175+
if ($day >= 1 && $day <= 31) {
176+
return substr("0{$day}", -2);
177+
}
178+
}
179+
}
180+
181+
return null;
182+
}
183+
184+
/**
185+
* Check if the first part is a prefix (eg 'BEF', 'ABT',).
186+
*
187+
* @param string $datePart Date part to be checked
188+
*
189+
* @return bool
190+
*/
191+
private function isPrefix($datePart)
192+
{
193+
return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
194+
}
98195
}

src/Record/Indi.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
namespace Gedcom\Record;
1616

17+
use \Gedcom\Record;
18+
19+
1720
/**
1821
* Class Indi.
1922
*/
@@ -135,21 +138,49 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable
135138
* @var Indi\Asso[]
136139
*/
137140
protected $asso = [];
138-
141+
139142
protected $birthday;
140-
143+
144+
protected $deathday;
145+
146+
protected $burialday;
147+
141148
public function setBirthday($birthday = '')
142149
{
143150
$this->birthday = $birthday;
144-
151+
145152
return $this;
146153
}
147-
154+
148155
public function getBirthday()
149156
{
150157
return $this->birthday;
151158
}
152159

160+
public function setDeathday($deathday = '')
161+
{
162+
$this->deathday = $deathday;
163+
164+
return $this;
165+
}
166+
167+
public function getDeathday()
168+
{
169+
return $this->deathday;
170+
}
171+
172+
public function setBurialday($burialday = '')
173+
{
174+
$this->burialday = $burialday;
175+
176+
return $this;
177+
}
178+
179+
public function getBurialday()
180+
{
181+
return $this->burialday;
182+
}
183+
153184
/**
154185
* @param string $id
155186
*

0 commit comments

Comments
 (0)