Skip to content

personnummer/meta

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

meta

Organization meta

Implementations

Package Pkg Version Spec Version Status Maintainer
Bash GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
C/C++ GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
C# GitHub release (latest by date) 3.0 Build status @Johannestegner
D GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
Dart GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
Elixir GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
Go GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
Haskell GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
Java GitHub release (latest by date) 3.0 GitHub Workflow @Johannestegner
JavaScript GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
Kotlin GitHub release (latest by date) 1.0 GitHub Workflow @Johannestegner
Lua GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
PHP GitHub release (latest by date) 3.0 GitHub Workflow Status @rasmusbe
Perl GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
Python GitHub release (latest by date) 3.0 GitHub Workflow @Buscedv
Ruby GitHub release (latest by date) 3.0 GitHub Workflow @VoxSecundus
Rust GitHub release (latest by date) 3.0 GitHub Workflow Status @bombsimon
Scala GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare
Swift GitHub release (latest by date) 1.0 GitHub Workflow @GoranLilja
V GitHub release (latest by date) 3.0 GitHub Workflow Status @frozzare

License Specification

We use the MIT license for all packages and the copyright row should look like this:

Copyright (c) Personnummer and Contributors

Package Specification (v1)

The personnummer package should have a valid method that can take both a number and a string as input.

personnummer.valid(string)
personnummer.valid(number)

Package Specification (v2)

The personnummer package should have a valid method that can take both a number and a string as input.

The second argument should be a optional boolean that exclude coordination number (Samordningsnummer) from validation.

personnummer.valid(string, [bool includeCoordinationNumber = true])
personnummer.valid(number, [bool includeCoordinationNumber = true])

The package should include a format method that can format the input value (string or number) as a short or long personnumer.

The second argument should be a optional boolean and true should format the input value as a long personnummer.

personnummer.format(number, [bool longFormat = false])
personnummer.format(string, [bool longFormat = false])

The package should include a getAge method that returns the age from a personnummer. For coordination number (Samordningsnummer) we should remove 60 to get the right age.

The second argument should be a optional boolean that exclude coordination number (Samordningsnummer) from validation.

personnummer.getAge(number, [bool includeCoordinationNumber = true])
personnummer.getAge(string, [bool includeCoordinationNumber = true])

Input value format

Dash or plus should be optional.

YYMMDD-XXXX
YYMMDD+XXXX
YYMMDDXXXX

YYYYMMDD-XXXX
YYYYMMDD+XXXX
YYYYMMDDXXXX

Coordination number (Samordningsnummer) should also be a valid personnummer.

Short format

Output for format method

YYMMDD-XXXX

Long format

Output for format method

YYYYMMDDXXXX

Package Specification (v2.1)

This specification adds new features and includes all parts from 2.0.

The package should include isMale and isFemale methods that can check if the personnummer or coordination number is a female or male.

personnummer.isMale(number|string, [bool includeCoordinationNumber = true])
personnummer.isFemale(number|string, [bool includeCoordinationNumber = true])

This methods should throw errors when input value is not a valid personnummer or coordination number.

Package Specification (v3)

Version 3 will contain breaking changes and will not be compatible with version 1 or 2.

Breaking changes

These functions will be moved into the class:

  • format
  • getAge
  • isFemale
  • isMale

Valid

The valid function can be a function or a static method on the class depending on language. The valid version that supports number arguments will be removed.

Class

The package should include a class that which should be the return value of parse

class Personnummer {
    public function __construct(string, array|object|languageSpecific)
}

Parse

The package should include a parse method that creates a new instance of the new class.

The parse and the class constructor should contain a second argument with options for the feature.

personnummer.parse(string, array|object|languageSpecific = []) => new class instance

The class should contain a static parse method that returns the class instance.

const pnr = Personnummer::parse(string, array|object|languageSpecific = [])

Coordination numbers

The coordination number option will be removed for all methods and be replaced with isCoordinationNumber method or property instead.

const pnr = personnummer.parse(string)

if (pnr.isCoordinationNumber()) {
    return
}

Error handling

All methods except for valid should throw an exception or return an error as a second return value. Error handling may be different depending on language. The exception/error class should be prefixed with Personnummer

Options

Options may be different depending on language.

Pseudo-interface

interface Personnummer {
    string century;
    string fullYear;
    string year;
    string month;
    string day;
    string sep;
    string num;
    string check;

    public function __construct(string ssn, array|object|languageSpecific options = []);

    public static function parse(string ssn);

    public function format(boolean longFormat) : string;
    public function getAge() : int;
    public function isFemale() : boolean;
    public function isMale() : boolean;
    public function isCoordinationNumber() : boolean;
}

function valid(string ssn) {
    try {
       parse(ssn)
       return true
    } catch (PersonnummerParseException) {
        return false
    }
}

function parse(string ssn, array|object|languageSpecific options = []) {
    return new Personnummer(ssn, options)
}