From 6b1009ecfde47d68859a202a2be8a1cde901f2fc Mon Sep 17 00:00:00 2001
From: Innei
Date: Mon, 16 Sep 2024 17:09:13 +0800
Subject: [PATCH] fix: format time locale fallback
Signed-off-by: Innei
---
src/renderer/src/components/ui/datetime/index.tsx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/renderer/src/components/ui/datetime/index.tsx b/src/renderer/src/components/ui/datetime/index.tsx
index 780ca9dece..17593368c7 100644
--- a/src/renderer/src/components/ui/datetime/index.tsx
+++ b/src/renderer/src/components/ui/datetime/index.tsx
@@ -104,7 +104,14 @@ export const RelativeDay = ({ date }: { date: Date }) => {
} else if (diffDays === 1) {
return t("time.yesterday")
} else {
- return date.toLocaleDateString(new Intl.Locale(language), {
+ let locale: Intl.Locale
+
+ try {
+ locale = new Intl.Locale(language.replace("_", "-"))
+ } catch {
+ locale = new Intl.Locale("en-US")
+ }
+ return date.toLocaleDateString(locale, {
weekday: "long",
month: "short",
day: "numeric",