Skip to content

Commit bd1dc2a

Browse files
committed
shared date validation
1 parent 7dcc35b commit bd1dc2a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/validation/src/se.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ export function validateOrganizationNumber(
8787
type PersonalIdentityNumberOptions = ValidatorOptions;
8888

8989
/**
90-
* Validates that the input value is a Swedish national identity number (fødselsnummer or d-nummer).
90+
* Validates that the input value is a Swedish national identity number (personnummer or samordningsnummer).
9191
*
9292
* It validates the control digits and checks if the date of birth is valid.
9393
*
9494
* @example
9595
* ```
96-
* // Fødselsnummer
96+
* // Personnummer
9797
* validatePersonalIdentityNumber('21075417753') // => true
9898
*
99-
* // D-nummer
99+
* // Samordningsnummer
100100
* validatePersonalIdentityNumber('53097248016') // => true
101101
* ```
102102
*/
@@ -130,6 +130,12 @@ export function validateNationalIdentityNumber(
130130
year = 2000;
131131
}
132132

133+
// for a d-number the day is increased by 40. Eg the 31st of a month would be 71, or the 3rd would be 43.
134+
// thus we need to subtract 40 to get the correct day of the month
135+
if (day > 40) {
136+
day = day - 40;
137+
}
138+
133139
return isValidDate(year, month, day);
134140
}
135141

packages/validation/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function mod10(value: string): boolean {
5757
}
5858

5959
export function isValidDate(year: number, month: number, day: number): boolean {
60-
// months are zero indexed 🤷‍♂️
60+
// biome-ignore lint/style/noParameterAssign: months are zero index 🤷‍♂️
6161
month -= 1;
6262

6363
// important to use UTC so the user's timezone doesn't affect the validation

0 commit comments

Comments
 (0)