A full-featured CRM built with React, shadcn/ui, and Supabase.
Add mention of Intl alternative and why we don't use it
fzaninotto4df6a70a6b1c
diff --git a/src/components/atomic-crm/misc/RelativeDate.tsx b/src/components/atomic-crm/misc/RelativeDate.tsxindex ea13f63f..9443074d 100644--- a/src/components/atomic-crm/misc/RelativeDate.tsx+++ b/src/components/atomic-crm/misc/RelativeDate.tsx@@ -3,16 +3,28 @@ import { differenceInDays, formatRelative } from "date-fns";import { enUS, fr } from "date-fns/locale";import { useLocaleState } from "ra-core";+/**+ * We use date-fns rather than Intl because Intl isn't yet capable of formatting relative dates as we want.+ *+ * The best we could do is this:+ *+ * const relativeDay = new Intl.RelativeTimeFormat(locale, {+ * numeric: "auto",+ * }).format(diffInDays, "day");+ *+ * const time = new Intl.DateTimeFormat(locale, {+ * hour: "numeric",+ * minute: "numeric",+ * }).format(dateObj);+ *+ * return `${relativeDay} ${time}`;+ *+ * This would return relatives dates as "3 days ago 3:00 PM" which isn't ideal. We want "3 days ago at 3:00 PM".+ */+const getDateFnsLocale = (locale: string) =>locale.startsWith("fr") ? fr : enUS;-export const formatLocalizedDate = (date: string, locale = "en") =>- new Intl.DateTimeFormat(locale, {- year: "numeric",- month: "long",- day: "numeric",- }).format(new Date(date));-export const formatRelativeDate = (date: string, locale = "en") => {const dateObj = new Date(date);const now = new Date();