fix(pwa+timezone)
Some checks failed
Deploy to Development / build-and-deploy (push) Has been cancelled
Deploy to Production / build-and-deploy (push) Successful in 1m32s

This commit is contained in:
EvanChal
2026-01-25 23:54:42 +01:00
parent e32b1ce04e
commit 02a54f5625
23 changed files with 579 additions and 85 deletions

View File

@@ -0,0 +1,66 @@
import { format, formatDistanceToNow } from 'date-fns'
import { fr } from 'date-fns/locale'
import { zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz'
// Fuseau horaire français
const FRENCH_TIMEZONE = 'Europe/Paris'
/**
* Convertit une date UTC en date du fuseau horaire français
*/
function toFrenchTimezone(date) {
if (!date) return null
const dateObj = date instanceof Date ? date : new Date(date)
return utcToZonedTime(dateObj, FRENCH_TIMEZONE)
}
/**
* Formate une date dans le fuseau horaire français
*/
export function formatDateInFrenchTimezone(date, formatStr = 'dd MMM à HH:mm') {
if (!date) return ''
const frenchDate = toFrenchTimezone(date)
return format(frenchDate, formatStr, { locale: fr })
}
/**
* Formate une date relative dans le fuseau horaire français
*/
export function formatRelativeDateInFrenchTimezone(date) {
if (!date) return ''
const frenchDate = toFrenchTimezone(date)
return formatDistanceToNow(frenchDate, { addSuffix: true, locale: fr })
}
/**
* Formate une date complète dans le fuseau horaire français
*/
export function formatFullDateInFrenchTimezone(date) {
return formatDateInFrenchTimezone(date, 'EEEE d MMMM yyyy à HH:mm')
}
/**
* Formate une date courte dans le fuseau horaire français
*/
export function formatShortDateInFrenchTimezone(date) {
return formatDateInFrenchTimezone(date, 'dd/MM/yyyy')
}
/**
* Formate une date pour un input datetime-local dans le fuseau horaire français
*/
export function formatDateForInputInFrenchTimezone(date) {
if (!date) return ''
const frenchDate = toFrenchTimezone(date)
return format(frenchDate, "yyyy-MM-dd'T'HH:mm", { locale: fr })
}
/**
* Convertit une date du fuseau horaire français vers UTC pour l'envoyer au backend
*/
export function convertFrenchTimezoneToUTC(date) {
if (!date) return null
const dateObj = date instanceof Date ? date : new Date(date)
return zonedTimeToUtc(dateObj, FRENCH_TIMEZONE)
}