Skip to content

Commit

Permalink
Add support for coordination numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
svenheden committed Dec 10, 2018
1 parent c608f15 commit 3ce0032
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const hasValidDate = (input: string) => {

const year = Number(yearStr);
const month = Number(monthStr) - 1;
const day = Number(dayStr);
let day = Number(dayStr);

if (day > 60) { // coordination numbers ("samordningsnummer")
day -= 60;
}

const date = new Date(year, month, day);

const yearIsValid = String(date.getFullYear()).substr(-2) === yearStr;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swedish-personal-identity-number-validator",
"version": "2.0.0",
"version": "2.1.0",
"title": "Swedish personal identity number validator",
"description": "Validates Swedish personal identity numbers",
"main": "dist/index.js",
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ test('personal identity numbers in the 10 digit format without the hyphen/plus s
assert.notOk(isValid('0908157892'));
assert.end();
});

test('coordination numbers', assert => {
assert.ok(isValid('701063-2391'));
assert.ok(isValid('640883-3231'));
assert.ok(isValid('7010632391'));
assert.ok(isValid('6408833231'));
assert.ok(isValid('19701063-2391'));
assert.ok(isValid('19640883-3231'));
assert.ok(isValid('197010632391'));
assert.ok(isValid('196408833231'));
assert.end();
});

0 comments on commit 3ce0032

Please sign in to comment.