dateOfBirthFromPesel function
returns date of birth from pesel number
throws InvalidPeselException if pesel number is invalid
Implementation
DateTime dateOfBirthFromPesel({
required String pesel,
}) {
if (!validatePesel(pesel: pesel)) {
throw InvalidPeselException();
}
final century = _getCentury(pesel);
final year = century.string() + pesel.substring(0, 2);
var month = pesel.substring(2, 4);
month = (int.parse(month) - century.monthOffset()).toString();
// month format - MM
if (month.length == 1) {
month = '0$month';
}
final day = pesel.substring(4, 6);
return DateTime.parse('$year-$month-$day');
}