|
1 | 1 | package dev.personnummer; |
2 | 2 |
|
| 3 | +import java.time.DateTimeException; |
3 | 4 | import java.time.LocalDate; |
4 | 5 | import java.time.LocalDateTime; |
5 | | -import java.time.format.DateTimeFormatter; |
6 | | -import java.time.format.DateTimeParseException; |
7 | 6 | import java.util.Objects; |
8 | 7 | import java.util.regex.*; |
9 | 8 |
|
@@ -157,9 +156,10 @@ public Personnummer(String personnummer, Options options) throws PersonnummerExc |
157 | 156 | this.controlNumber = matches.group(7); |
158 | 157 |
|
159 | 158 | try { |
160 | | - DateTimeFormatter.ofPattern("yyyy MM dd").parse(String.format("%s %s %02d", this.fullYear, this.month, this.realDay)); |
161 | | - } catch (DateTimeParseException e) { |
162 | | - throw new PersonnummerException("Invalid personal identity number."); |
| 159 | + //noinspection ResultOfMethodCallIgnored |
| 160 | + LocalDate.of(Integer.parseInt(this.fullYear), Integer.parseInt(this.month), this.realDay); |
| 161 | + } catch (DateTimeException e) { |
| 162 | + throw new PersonnummerException("Invalid personal identity number: " + e.getMessage()); |
163 | 163 | } |
164 | 164 |
|
165 | 165 | this.isMale = Integer.parseInt(Character.toString(this.numbers.charAt(2))) % 2 == 1; |
@@ -191,7 +191,7 @@ public Personnummer(String personnummer) throws PersonnummerException { |
191 | 191 | public String toString() { |
192 | 192 | return format(); |
193 | 193 | } |
194 | | - |
| 194 | + |
195 | 195 | /** |
196 | 196 | * get a DateTime object from the Peronnummer object's date values of Date Month and Time. |
197 | 197 | * @return DateTime object from the personnummer object |
|
0 commit comments