From a08d0c0e9bfb31879bc2b6933953c86cb0541b84 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 24 Sep 2024 18:37:04 +0200 Subject: [PATCH] fix #100 (#180) Close #100 We use Intl.DateTimeFormat to format the date, using the local provided from 1st: the guild info 2nd: the default lang used for Botanique Reviewed-on: https://git.mylloon.fr/ConfrerieDuKassoulait/Botanique/pulls/180 Co-authored-by: Mylloon Co-committed-by: Mylloon --- src/utils/time.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/time.ts b/src/utils/time.ts index 61f8a88..a640cc8 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -5,8 +5,16 @@ * @param date Date * @returns String */ -export const showDate = (tz: string, locale: Map, date: Date) => - date.toLocaleString(tz).replace(" ", ` ${locale.get("u_time_at")} `); +export const showDate = (tz: string, locale: Map, date: Date) => { + const formattedDate = new Intl.DateTimeFormat(tz, { + dateStyle: "short", + timeStyle: "medium", + }) + .format(date) + .split(" "); + + return `${formattedDate[0]} ${locale.get("u_time_at")} ${formattedDate[1]}`; +}; enum TimeSecond { Year = 31536000, @@ -63,5 +71,6 @@ export const strToSeconds = (time: string) => { export const timeDeltaToString = (time: number) => { const now = Date.now(); // TODO adapt the output and not always parse the time as seconds + // Use Intl.RelativeTimeFormat ? return `${strToSeconds(`${(now - time) / 1000}`)} secs`; };