Working on the README.md

This commit is contained in:
charlesgauthereau
2025-11-08 20:07:49 +01:00
parent cf8e5b7094
commit 4644ed2f41
25 changed files with 514 additions and 88 deletions
+26 -11
View File
@@ -1,7 +1,29 @@
import {format, formatDistanceToNow} from "date-fns";
import {formatDistanceToNow} from "date-fns";
/**
* Get user's locale and timezone from the browser
*/
const TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
const LOCALE = Intl.DateTimeFormat().resolvedOptions().locale;
/**
* Format a date in DD/MM/YYYY HH:mm 24-hour format
*/
export function formatLocalizedDate(date: string | number | Date) {
const d = new Date(date);
return new Intl.DateTimeFormat(LOCALE, {
day: "2-digit",
month: "2-digit",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
hour12: false, // 24-hour format
timeZone: TIMEZONE,
}).format(d);
}
export function humanReadableDate(rawDate: string | number | Date) {
return formatFrenchDate(rawDate);
return formatLocalizedDate(rawDate);
}
export function timeAgo(rawDate: string | number | Date) {
@@ -10,14 +32,7 @@ export function timeAgo(rawDate: string | number | Date) {
}
export function formatDateLastContact(lastContact: string | number | Date | null) {
console.log(lastContact)
return lastContact
? formatFrenchDate(lastContact)
: "Never connected."
? formatLocalizedDate(lastContact)
: "Never connected.";
}
export function formatFrenchDate(date: string | number | Date) {
return new Date(date).toLocaleString("fr-FR", {
timeZone: "Europe/Paris",
});
}