From 3ce0032b92017d05019b166b6b246664d3b9f2cc Mon Sep 17 00:00:00 2001
From: Jonathan Svenheden <jonathan@svenheden.com>
Date: Mon, 10 Dec 2018 19:41:44 +0100
Subject: [PATCH] Add support for coordination numbers

https://www.skatteverket.se/privat/skatter/internationellt/bosattutomlands/samordningsnummer.4.53a97fe91163dfce2da80001279.html
---
 index.ts          |  7 ++++++-
 package-lock.json |  2 +-
 package.json      |  2 +-
 test.js           | 12 ++++++++++++
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/index.ts b/index.ts
index d259156..e7cca3c 100644
--- a/index.ts
+++ b/index.ts
@@ -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;
diff --git a/package-lock.json b/package-lock.json
index cf7ec10..eacaf02 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "swedish-personal-identity-number-validator",
-  "version": "2.0.0",
+  "version": "2.1.0",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index 8a3a298..df3deb4 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/test.js b/test.js
index b61d5ea..0a20483 100644
--- a/test.js
+++ b/test.js
@@ -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();
+});
\ No newline at end of file