mathiasvr / danish-ssn Goto Github PK
View Code? Open in Web Editor NEWValidate and generate danish social security numbers (cpr-nummer)
License: MIT License
Validate and generate danish social security numbers (cpr-nummer)
License: MIT License
I went to the following site:
http://id-check.artega.biz/index.php
I entered birthdate June 20, 2000 and used the first CPR found one the list: 200600-0005
According to your library component, when using the info("200600-0005").date I receive:
Wed Jun 20 1900 00:00:00 GMT+0300 (EEST)
The year 2000 was a leap year and when a person is born with the cpr 2902004001 his birthdate is calculate to 2000-03-01.
To fix the getDate needs to change, a suggestion:
function is1900Or2000(digit7) {
return digit7 === 4 || digit7 === 9;
}
function is1800Or1900(digit7) {
return digit7 > 4;
}
function toDate(year, month, day) {
return new Date(Date.UTC(year, month - 1, day, 0, 0, 0, 0));
}
function calculateYear(digit7, dateSegments) {
var year = toDate(dateSegments[2], dateSegments[1], dateSegments[0]).getFullYear();
if (is1900Or2000(digit7)) {
if (year <= 1936) {
return year + 100;
}
} else if (is1800Or1900(digit7)) {
return year > 1957 ? year - 100 : year + 100;
}
return year;
}
function getDate(cpr) {
var dateSegments = cpr.substring(0, 6).match(/.{1,2}/g);
return toDate(calculateYear(parseInt(cpr[6], 10), dateSegments), dateSegments[1], dateSegments[0]);
}
And this can be added to the test:
JSON.stringify(cpr("2902004001")) ===
JSON.stringify({ cpr: "2902004001", valid: true, date: new Date("2000-02-29T00:00:00.000Z"), sex: "Male" })
First of all, thank you for the library, the rules for danish SSN date extraction are not the easiest to understand - your library helped me a lot.
The latest version has an issue on validForDate
, it thorws:
TypeError: date.getFullYear(...).slice is not a function
I've created a fix for that and will create now a pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.