We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4df1ac7 + 35aad18 commit 11c3b04Copy full SHA for 11c3b04
1 file changed
src/lib.rs
@@ -137,9 +137,10 @@ impl Personnummer {
137
self.date.month(),
138
self.date.day()
139
);
140
+
141
let to_control = format!("{:06}{:03}", ymd, self.serial);
142
- luhn(to_control) == self.control
143
+ self.serial > 0 && luhn(to_control) == self.control
144
}
145
146
/// Return the age of the person holding the personal identity number. The dates used for the
@@ -211,7 +212,12 @@ mod tests {
211
212
213
#[test]
214
fn test_valid_date_invalid_digits() {
- let cases = vec!["19900101-1111", "20160229-1111", "6403273814"];
215
+ let cases = vec![
216
+ "19900101-1111",
217
+ "20160229-1111",
218
+ "6403273814",
219
+ "20150916-0006",
220
+ ];
221
222
for tc in cases {
223
assert!(!Personnummer::new(tc).valid());
0 commit comments