tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
handle failed locale from header
awarm.space
4 months ago
d6f6eb96
0ba0db6f
+10
-2
1 changed file
expand all
collapse all
unified
split
src
hooks
useLocalizedDate.ts
+10
-2
src/hooks/useLocalizedDate.ts
···
36
36
dateTime = dateTime.setZone(effectiveTimezone);
37
37
}
38
38
39
39
+
// On initial page load, use header locale. After hydration, use system locale
39
40
// Parse locale from accept-language header (take first locale)
40
41
// accept-language format: "en-US,en;q=0.9,es;q=0.8"
41
41
-
const locale = language?.split(",")[0]?.split(";")[0]?.trim() || "en-US";
42
42
+
const effectiveLocale = isInitialPageLoad
43
43
+
? language?.split(",")[0]?.split(";")[0]?.trim() || "en-US"
44
44
+
: Intl.DateTimeFormat().resolvedOptions().locale;
42
45
43
43
-
return dateTime.toLocaleString(options, { locale });
46
46
+
try {
47
47
+
return dateTime.toLocaleString(options, { locale: effectiveLocale });
48
48
+
} catch (error) {
49
49
+
// Fallback to en-US if locale is invalid
50
50
+
return dateTime.toLocaleString(options, { locale: "en-US" });
51
51
+
}
44
52
}, [dateString, options, timezone, language, isInitialPageLoad]);
45
53
}