Git Product home page Git Product logo

danish-ssn's People

Contributors

mathiasvr avatar rafarovina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

danish-ssn's Issues

2000 was a leap year

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" })

validForDate does not work

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.