Skip to content

Implement spec 3.1: interim numbers, get_date and options - #42

Merged
rasmusbe merged 1 commit into
mainfrom
feature/spec-3.1
Nov 13, 2026
Merged

rasmusbe merged 1 commit into
mainfrom
feature/spec-3.1

Conversation

@rasmusbe

Copy link
Copy Markdown
Member

Implements version 3.1 of the package specification (https://github.com/personnummer/meta#package-specification-v31). The package has been on spec 3 until now.

What 3.1 adds:

  • Interim numbers, YYMMDD-Xnnn with one of the letters TRSUWXJKLMN. The letter counts as 1 in the Luhn check and format keeps it. is_interim tells them apart, the way is_coord does for coordination numbers.
  • get_date, which returns a Date. For coordination numbers the 60 is subtracted from the day. get_age uses it.
  • Options for parse, the constructor and valid?: allow_coordination_number (default true) and allow_interim_number (default false). Interim numbers are rejected unless the option is set, so no input that was invalid before is valid by default now.

Also in this PR:

  • Personnummer.parse dropped the options it was given (Personnummer.new(personnummer, options={})). It passes them on now.
  • The regex is anchored. Before, Personnummer.valid?("xx8507099805yy") was true.
  • Errors are raised as Personnummer::Error. It inherits from RuntimeError, so an existing rescue RuntimeError still catches it.

valid? still takes the old flag as its second argument, so Personnummer.valid?(number, false) works as before.

The interim tests generate the valid cases in testdata/interim.json in the meta repo from the eleven letters, and the invalid one is written out. The existing tests are unchanged.

I have only run the tests on Ruby 3.4. The version and .meta.yaml are not changed here, that is for the release PR.

Accept interim numbers (the letters TRSUWXJKLMN, counted as 1 in the Luhn check) behind the allow_interim_number option, and add is_interim and get_date. parse, the constructor and valid? take an options hash with allow_coordination_number and allow_interim_number. parse used to drop the options it was given.

valid? still accepts the old include_coord flag as its second argument. The regex is now anchored, so input with leading or trailing characters is invalid. Errors are raised as Personnummer::Error, a RuntimeError.
@rasmusbe
rasmusbe merged commit f3d94fc into main Nov 13, 2026
4 checks passed
@rasmusbe rasmusbe mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant