From 22ef39c7fbed7b93cc306a42921cb0626a4c4535 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Tue, 8 Feb 2022 15:32:15 +0100 Subject: [PATCH] GREG-171: Having cutoff date for when to attempt suggestion --- frontend/src/utils/index.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index b8fedc45..746d2a28 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -240,11 +240,26 @@ export function isFemaleBasedOnNationalId(nationalId: string): boolean { return parseInt(nationalId.charAt(8), 10) % 2 === 0 } +/** + * The ID-number format is scheduled to change in the future: + * https://www.skatteetaten.no/deling/opplysninger/folkeregisteropplysninger/pid/ + * + * Do not attempt a suggestion if we are at the time when the format will change. + */ +function shouldAttemptSuggestion(): boolean { + const currentYear = getYear(new Date()) + + // Keeping it simple, if this code is still running and should be revised. + // The new numbers are scheduled to appear in 2032 + return currentYear <= 2031 +} + export function extractGenderOrBlank(nationalId?: string): string { if ( nationalId == null || nationalId === '' || - isValidFnr(nationalId) !== true + isValidFnr(nationalId) !== true || + !shouldAttemptSuggestion() ) { return '' } @@ -300,7 +315,8 @@ export function extractBirthdateFromNationalId( if ( nationalId == null || nationalId === '' || - isValidFnr(nationalId) !== true + isValidFnr(nationalId) !== true || + !shouldAttemptSuggestion() ) { return null } -- GitLab