Skip to content

Commit 0ff80b5

Browse files
authored
Merge pull request #6 from esyede/main
fix: date of birth parser
2 parents 2ebd705 + e862ea2 commit 0ff80b5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/Reader.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,23 @@ public function getKecamatan()
133133
*/
134134
public function getTanggalLahir()
135135
{
136-
$code = substr($this->nik, 6, 12);
136+
$code = substr($this->nik, 6, 6);
137137
list($day, $month, $year) = str_split($code, 2);
138138

139+
$day = (((int) $day - 40) > 0) ? ($day - 40) : $day;
140+
141+
$max = date('Y') - 17;
142+
$min = 1945;
143+
$temp = '20' . $year;
144+
$low = '19' . $year;
145+
$high = '20' . $year;
146+
147+
$year = ($temp > $min) ? (($high > $max) ? $low : $high) : $low;
148+
149+
if ($year < $min) {
150+
throw new Exceptions\InvalidDateOfBirthException('Error! year: ' . $year);
151+
}
152+
139153
try {
140154
return DateTime::createFromFormat(
141155
'd-m-Y',

0 commit comments

Comments
 (0)