-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Legger inn støtte for datoer på format ddmmyy i DateInputWrapper
- Loading branch information
Showing
18 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/aap-felles-react/src/Form/dateinputwrapper/dateMapper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { mapShortDateToDateString } from './dateMapper'; | ||
|
||
describe('dateMapper', () => { | ||
test('returnerer input dersom verdien inneholder noe annet enn tall', () => { | ||
const input = 'Hei, dette var da ikke en dato'; | ||
expect(mapShortDateToDateString(input)).toEqual(input); | ||
}); | ||
|
||
test('returnerer input dersom det er en dato på format dd.mm.åååå', () => { | ||
const input = '19.12.2023'; | ||
expect(mapShortDateToDateString(input)).toEqual(input); | ||
}); | ||
|
||
test('returnerer 19.07.2022 når input er 190722', () => { | ||
expect(mapShortDateToDateString('190722')).toEqual('19.07.2022'); | ||
}); | ||
|
||
test('returnerer 19.07.1987 når input er 190787', () => { | ||
expect(mapShortDateToDateString('190787')).toEqual('19.07.1987'); | ||
}); | ||
|
||
test('returnerer 31.12.1999 når input er 311299', () => { | ||
expect(mapShortDateToDateString('311299')).toEqual('31.12.1999'); | ||
}); | ||
|
||
test('returnerer 01.01.2000 når input er 010100', () => { | ||
expect(mapShortDateToDateString('010100')).toEqual('01.01.2000'); | ||
}); | ||
|
||
test('returnerer 31.03.2006 når input er 310306', () => { | ||
expect(mapShortDateToDateString('310306')).toEqual('31.03.2006'); | ||
}); | ||
|
||
test('returnerer en dato fra år 20xx når årstallet er for 90 år siden eller mer', () => { | ||
const nittiÅrSiden = new Date().getFullYear() - 90 - 1900; | ||
expect(mapShortDateToDateString(`3103${nittiÅrSiden}`)).toEqual(`31.03.20${nittiÅrSiden}`); | ||
}); | ||
|
||
test('returnerer en dato fra 19xx når årstallet er under 90 år siden', () => { | ||
const åttiniÅrSiden = new Date().getFullYear() - 89 - 1900; | ||
expect(mapShortDateToDateString(`3103${åttiniÅrSiden}`)).toEqual(`31.03.19${åttiniÅrSiden}`); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/aap-felles-react/src/Form/dateinputwrapper/dateMapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* konverterer en dato på formatet ddmmyy til dd.mm.yyyy | ||
* årstall inntill 90 år tilbake i tid antar vi skal starte med 19 | ||
* Gir input tilbake dersom det ikke er kun tall eller noe annet enn 6 tegn | ||
*/ | ||
export const mapShortDateToDateString = (input: string): string => { | ||
const inputIsNumeric = /^\d+$/.test(input); | ||
if (!inputIsNumeric || input.length !== 6) { | ||
return input; | ||
} | ||
|
||
const date = input.substring(0, 2); | ||
const month = input.substring(2, 4); | ||
|
||
const year = Number.parseInt(input.substring(4), 10); | ||
const flipYear = new Date().getFullYear() - 90; | ||
const shortFlipYear = flipYear % 100; | ||
const fullYear = year > shortFlipYear ? 1900 + year : 2000 + year; | ||
|
||
return `${date}.${month}.${fullYear}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters