diff --git a/site/source/domain/Date.spec.ts b/site/source/domain/Date.spec.ts index 9aae1337b..0ebc41efa 100644 --- a/site/source/domain/Date.spec.ts +++ b/site/source/domain/Date.spec.ts @@ -1,17 +1,22 @@ import { describe, expect, it } from 'vitest' -import { formatDate, parsePublicodesDateString } from '@/domain/Date' +import { + parsePublicodesDateString, + PublicodeDate, + toPublicodeDate, +} from '@/domain/Date' describe('parsePublicodesDateString', () => { it('comprend 24-12-2024 comme le 24 décembre 2024', () => { - expect(parsePublicodesDateString('24/12/2024')).toEqual( + const publiCodeDate: PublicodeDate = '24/12/2024' + expect(parsePublicodesDateString(publiCodeDate)).toEqual( new Date(2024, 11, 24) ) }) }) -describe('formatDate', () => { +describe('toPublicodeDate', () => { it("écrit le 15 août 1980 comme '15/08/1980' (format Publicodes)", () => { - expect(formatDate(new Date('1980-08-15'))).toEqual('15/08/1980') + expect(toPublicodeDate(new Date('1980-08-15'))).toEqual('15/08/1980') }) }) diff --git a/site/source/domain/Date.ts b/site/source/domain/Date.ts index bb5306484..963840b66 100644 --- a/site/source/domain/Date.ts +++ b/site/source/domain/Date.ts @@ -1,10 +1,18 @@ import { format, parse } from 'date-fns/fp' +export type PublicodeDate = + `${number}${number}/${number}${number}/${number}${number}${number}${number}` export const publicodesStandardDateFormat = 'dd/MM/yyyy' -export const formatDate = format(publicodesStandardDateFormat) +type DateToPublicodeDate = (d: Date) => PublicodeDate + +export const toPublicodeDate = format( + publicodesStandardDateFormat +) as DateToPublicodeDate + +type PublicodeDateToDate = (d: PublicodeDate) => Date export const parsePublicodesDateString = parse( new Date(), publicodesStandardDateFormat -) +) as PublicodeDateToDate diff --git a/site/source/store/reducers/companySituationReducer.ts b/site/source/store/reducers/companySituationReducer.ts index 34d3fde1d..d45f10279 100644 --- a/site/source/store/reducers/companySituationReducer.ts +++ b/site/source/store/reducers/companySituationReducer.ts @@ -1,7 +1,7 @@ import { DottedName } from 'modele-social' import { CodeCatégorieJuridique } from '@/domain/CodeCatégorieJuridique' -import { formatDate } from '@/domain/Date' +import { toPublicodeDate } from '@/domain/Date' import { Entreprise } from '@/domain/Entreprise' import { Action } from '@/store/actions/actions' import { buildSituationFromObject, omit } from '@/utils' @@ -85,7 +85,7 @@ export function companySituation(state: Situation = {}, action: Action) { export function getCompanySituation(entreprise: Entreprise): Situation { return { - 'entreprise . date de création': formatDate(entreprise.dateDeCréation), + 'entreprise . date de création': toPublicodeDate(entreprise.dateDeCréation), 'entreprise . catégorie juridique': `'${getCatégorieFromCode( entreprise.codeCatégorieJuridique )}'`,