Fix 24h time prefixing early morning hours with 0
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run

This commit is contained in:
Kalle 2025-11-09 15:25:19 +02:00
parent 94dca199fb
commit 5cb7305c10

View File

@ -59,9 +59,17 @@ export function useTimeFormat() {
const clockFormat = user?.preferences?.clockFormat;
const clockOptions = getClockFormatOptions(clockFormat, i18n.language);
const language = () => {
// this is needed to ensure the time format used doesn't say e.g. "03:00" when we want "3:00"
if (clockFormat === "24h" && i18n.language === "en") {
return "en-GB";
}
return i18n.language;
};
const formatDateTime = (date: Date, options?: Intl.DateTimeFormatOptions) => {
return date.toLocaleString(
i18n.language,
language(),
options?.hour
? {
...options,
@ -74,14 +82,14 @@ export function useTimeFormat() {
};
const formatTime = (date: Date, options?: Intl.DateTimeFormatOptions) => {
return date.toLocaleTimeString(i18n.language, {
return date.toLocaleTimeString(language(), {
...options,
...clockOptions,
});
};
const formatDate = (date: Date, options?: Intl.DateTimeFormatOptions) => {
return date.toLocaleDateString(i18n.language, options);
return date.toLocaleDateString(language(), options);
};
return { formatDateTime, formatTime, formatDate };