Skip to content

Commit a4ada9a

Browse files
authored
fix: 1228 correction removing dayjs (#1139)
## Ticket(s) lié(s) 1228 ## Description Fix d'une régression suite à suppression de dayJs Ajout d'une fonction date de remplacement + test
1 parent 71189fd commit a4ada9a

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

packages/frontend-usagers/src/components/organisme/personne-morale.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
Inactif depuis le
9090
{{
9191
historic?.updatedAt
92-
? setFormatDateToFRString(new Date(historic.updatedAt))
92+
? formatFR(new Date(historic.updatedAt))
9393
: ""
9494
}}
9595
</div>
@@ -336,14 +336,15 @@
336336
import { useField, useForm } from "vee-validate";
337337
import * as yup from "yup";
338338
import { IsDownloading, ApiUnavailable } from "@vao/shared-ui";
339-
import { setFormatDateToFRString } from "@vao/shared-bridge";
340339
import { apiTypes } from "@vao/shared-ui/src/models";
341340
import type { PersonneMoraleDto } from "@vao/shared-bridge";
342341
import { SiretService } from "../../services/siretService";
343342
import {
344343
ERRORS_SIRET_MESSAGES,
345344
ERRORS_SIRET,
346345
formatSiret,
346+
formatFR,
347+
formatFRDateTime,
347348
} from "@vao/shared-bridge";
348349
349350
const toaster = useToaster();
@@ -393,7 +394,7 @@ const usersWithSiret = computed(() =>
393394
user.nom,
394395
user.prenom,
395396
user.email,
396-
dayjs(user.dateCreation).format("DD/MM/YYYY HH:MM"),
397+
formatFRDateTime(new Date(user.dateCreation)),
397398
]),
398399
);
399400

packages/frontend-usagers/src/components/organisme/personne-physique.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
Inactif depuis le
8080
{{
8181
historic?.updatedAt
82-
? setFormatDateToFRString(new Date(historic.updatedAt))
82+
? formatFR(new Date(historic.updatedAt))
8383
: ""
8484
}}
8585
</div>
@@ -240,7 +240,6 @@
240240

241241
<script setup lang="ts">
242242
import { useField, useForm } from "vee-validate";
243-
import { setFormatDateToFRString } from "@vao/shared-bridge";
244243
import * as yup from "yup";
245244
import { IsDownloading, ApiUnavailable } from "@vao/shared-ui";
246245
import { apiTypes } from "@vao/shared-ui/src/models";
@@ -249,6 +248,7 @@ import {
249248
ERRORS_SIRET_MESSAGES,
250249
ERRORS_SIRET,
251250
formatSiret,
251+
formatFR,
252252
} from "@vao/shared-bridge";
253253
254254
const toaster = useToaster();

packages/shared-bridge/src/utils/date.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import {
22
addDays,
33
addMonths,
4+
formatFR,
5+
formatFRDateTime,
46
isAfter,
57
isBefore,
6-
setFormatDateToFRString,
78
} from "./date";
89

910
describe("setFormatDateToFRString", () => {
1011
it("should format date to FR string", () => {
11-
expect(setFormatDateToFRString(new Date(2023, 0, 1))).toBe("01/01/2023");
12+
expect(formatFR(new Date(2023, 0, 1))).toBe("01/01/2023");
13+
});
14+
});
15+
16+
describe("setFormatDateAndTimeToFRString", () => {
17+
it("should format date and time to FR string", () => {
18+
expect(formatFRDateTime(new Date(2023, 0, 1, 21, 5))).toBe(
19+
"01/01/2023 21:05",
20+
);
1221
});
1322
});
1423

packages/shared-bridge/src/utils/date.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dayjs from "dayjs";
2+
13
export function isBefore(
24
date: string | number | Date,
35
dateToCompare: string | number | Date,
@@ -19,10 +21,10 @@ export function addDays(date: Date, days: number) {
1921
export function addMonths(date: Date, months: number) {
2022
return addDays(date, 30 * months);
2123
}
24+
export function formatFR(date: Date) {
25+
return dayjs(date).format("DD/MM/YYYY");
26+
}
2227

23-
export function setFormatDateToFRString(date: Date) {
24-
const day = String(date.getDate()).padStart(2, "0");
25-
const month = String(date.getMonth() + 1).padStart(2, "0");
26-
const year = date.getFullYear();
27-
return `${day}/${month}/${year}`;
28+
export function formatFRDateTime(date: Date) {
29+
return dayjs(date).format("DD/MM/YYYY HH:mm");
2830
}

0 commit comments

Comments
 (0)