refactor(front) : formatDateFr mutualisé dans shared/utils/date + rendu déterministe (ERP-191)
Pull Request — Quality gate / Frontend (lint + Vitest + build) (pull_request) Successful in 1m33s
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 5m19s

Trois copies identiques de formatDateFr (logistique weighingTicketFormat,
transport carriers/index, CarrierQualimatTab) fusionnées en un seul helper
partagé. La nouvelle version lit la date directement dans la chaîne ISO (10
premiers caractères) au lieu de new Date(value).getDate() : un datetime porteur
d'un offset (…+02:00, …Z) ne bascule plus d'un jour selon le fuseau du
navigateur / runner CI, et reste cohérent avec l'écran d'édition (slice) et
l'export serveur (format d/m/Y).

weighingTicketFormat ré-exporte le helper (imports inchangés côté écrans).
Tests de déterminisme fuseau ajoutés dans shared/utils/date.test.ts.
This commit is contained in:
2026-06-24 16:22:28 +02:00
parent 9b476f22bb
commit 87513d130a
5 changed files with 50 additions and 45 deletions
@@ -5,23 +5,9 @@
* mettre en forme la valeur déjà normalisée renvoyée par l'API.
*/
/**
* Date courte française `JJ-MM-AAAA` (spec M5). Chaîne vide si la valeur est
* absente ou invalide. Lit les composantes locales (cohérent avec l'affichage
* des autres répertoires M1→M4).
*/
export function formatDateFr(value: string | null | undefined): string {
if (!value) {
return ''
}
const date = new Date(value)
if (Number.isNaN(date.getTime())) {
return ''
}
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
return `${day}-${month}-${date.getFullYear()}`
}
// Date courte française `JJ-MM-AAAA` (spec M5) : helper partagé inter-modules
// (mutualisé avec les répertoires M1→M4). Re-exporté ici pour les écrans M5.
export { formatDateFr } from '~/shared/utils/date'
/**
* Poids en kg avec séparateur de milliers (espace) + suffixe « Kg »
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { debounce } from '~/shared/utils/debounce'
import { formatDateFr } from '~/shared/utils/date'
import { useQualimatSearch, type QualimatCarrierRow } from '~/modules/transport/composables/useQualimatSearch'
/**
@@ -92,19 +93,6 @@ function isExpired(value: string): boolean {
return date.getTime() < today.getTime()
}
/** Format court français JJ-MM-AAAA (chaîne vide si date absente / invalide). */
function formatDateFr(value: string | null | undefined): string {
if (!value) {
return ''
}
const date = new Date(value)
if (Number.isNaN(date.getTime())) {
return ''
}
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
return `${day}-${month}-${date.getFullYear()}`
}
// ── Confirmation d'intégration ───────────────────────────────────────────────
const confirmOpen = ref(false)
@@ -141,6 +141,7 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { formatDateFr } from '~/shared/utils/date'
interface FilterOption {
value: string
@@ -235,20 +236,6 @@ function isValidityExpired(item: Record<string, unknown>): boolean {
return date.getTime() < today.getTime()
}
/** Format court francais JJ-MM-AAAA (spec M4). Chaine vide si date absente / invalide. */
function formatDateFr(value: string | null | undefined): string {
if (!value) {
return ''
}
const date = new Date(value)
if (Number.isNaN(date.getTime())) {
return ''
}
const day = String(date.getDate()).padStart(2, '0')
const month = String(date.getMonth() + 1).padStart(2, '0')
return `${day}-${month}-${date.getFullYear()}`
}
/** Clic sur une ligne → ecran Consultation (route a plat /carriers/{id}). */
function onRowClick(item: Record<string, unknown>): void {
router.push(`/carriers/${item.id}`)