SV-Nummer: Ersatznummern mit Monat 13 sind gueltig
Sind fuer ein Geburtsdatum alle laufenden Nummern vergeben, vergibt die Sozialversicherung eine Ersatznummer mit dem Monat 13 im TTMMJJ-Teil. Formular, Import und Datenbank wiesen sie als ungueltiges Datum ab. Monat 13 ist jetzt zulaessig (Tag 1 bis 31), in lib/svnr.ts und in is_valid_svnr (Migration 20261110120000). Die Pruefziffer bleibt Bedingung. Bei einer Ersatznummer entfaellt der Vergleich mit dem Geburtsdatum, der Hinweis waere immer falsch. Geprueft: lint, tsc, types:check, npm test, waechter; Migrationen auf leerer Datenbank zweimal (zweiter Lauf: nichts anzuwenden), Selbstpruefung der Migration, rauchtest.sql und vertragsangaben.sql.
This commit is contained in:
13
lib/svnr.ts
13
lib/svnr.ts
@@ -13,6 +13,11 @@
|
||||
const WEIGHTS = [3, 7, 9, 0, 5, 8, 4, 2, 1, 6] as const;
|
||||
const CHECK_INDEX = 3;
|
||||
|
||||
// Sind für ein Geburtsdatum alle laufenden Nummern vergeben, vergibt die
|
||||
// Sozialversicherung eine Ersatznummer mit dem Monat 13 im TTMMJJ-Teil. Sie ist
|
||||
// eine gültige Nummer; die Prüfziffer wird wie bei jeder anderen gerechnet.
|
||||
const ERSATZMONAT = 13;
|
||||
|
||||
export type SvnrError = "length" | "serial" | "checksum" | "date" | "birthDateMismatch";
|
||||
|
||||
const MESSAGES: Record<SvnrError, string> = {
|
||||
@@ -105,15 +110,17 @@ export function validateSvnr(input: string, birthDate?: string | null): SvnrErro
|
||||
|
||||
const day = Number(n.slice(4, 6));
|
||||
const month = Number(n.slice(6, 8));
|
||||
if (month < 1 || month > 12 || day < 1 || day > 31) return "date";
|
||||
if (month < 1 || month > ERSATZMONAT || day < 1 || day > 31) return "date";
|
||||
// Without a century the tail cannot be resolved to a real date, so the
|
||||
// day-of-month bound is the generous one; a supplied birthDate settles it.
|
||||
if (day > [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]) return "date";
|
||||
if (month !== ERSATZMONAT && day > [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]) return "date";
|
||||
|
||||
const expected = svnrCheckDigit(n);
|
||||
if (expected === null || expected !== Number(n[CHECK_INDEX])) return "checksum";
|
||||
|
||||
if (birthDate) {
|
||||
// Eine Ersatznummer trägt kein Geburtsdatum, ein Vergleich ergäbe immer
|
||||
// eine Abweichung.
|
||||
if (birthDate && month !== ERSATZMONAT) {
|
||||
const [y, m, d] = birthDate.split("-");
|
||||
if (d !== n.slice(4, 6) || m !== n.slice(6, 8) || y?.slice(-2) !== n.slice(8, 10)) return "birthDateMismatch";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user