2121 */
2222class 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}
0 commit comments