feat: format date and time in /admin/users/ -> Profile section (#20811)

Matches the format used in the user settings page.

Added a formatting function in utils.
This commit is contained in:
Mirek
2025-08-11 23:50:34 +02:00
committed by GitHub
parent 24db881c14
commit 5d2777a5c6
3 changed files with 49 additions and 18 deletions

View File

@@ -36,6 +36,12 @@ interface DownloadRequestOptions<T = unknown> {
onDownloadProgress?: (event: ProgressEvent<XMLHttpRequestEventTarget>) => void;
}
interface DateFormatter {
formatDate: (date: Date) => string;
formatTime: (date: Date) => string;
formatDateTime: (date: Date) => string;
}
export const initLanguage = async () => {
const preferenceLang = get(lang);
for (const { code, loader } of langs) {
@@ -343,3 +349,35 @@ export const withError = async <T>(fn: () => Promise<T>): Promise<[undefined, T]
// eslint-disable-next-line unicorn/prefer-code-point
export const decodeBase64 = (data: string) => Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
export function createDateFormatter(localeCode: string | undefined): DateFormatter {
return {
formatDate: (date: Date): string =>
date.toLocaleString(localeCode, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}),
formatTime: (date: Date): string =>
date.toLocaleString(localeCode, {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}),
formatDateTime: (date: Date): string => {
const formattedDate = date.toLocaleString(localeCode, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
});
const formattedTime = date.toLocaleString(localeCode, {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
return `${formattedDate} ${formattedTime}`;
},
};
}