mirror of
https://github.com/immich-app/immich.git
synced 2025-12-20 09:15:35 +03:00
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:
@@ -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}`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user