This commit is contained in:
talorr
2026-03-27 03:36:08 +03:00
parent 8a97ce6d54
commit cda36918e8
225 changed files with 35641 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
type BrowserDateTimeOptions = Intl.DateTimeFormatOptions;
const DEFAULT_DATE_TIME_OPTIONS: BrowserDateTimeOptions = {
day: "2-digit",
month: "2-digit",
year: "numeric",
hour: "2-digit",
minute: "2-digit"
};
export function useBrowserDateTime() {
const browserTimeZone = useState<string | null>("browser-time-zone", () => null);
onMounted(() => {
browserTimeZone.value = Intl.DateTimeFormat().resolvedOptions().timeZone || null;
});
const formatDateTime = (value: string | Date | null | undefined, options: BrowserDateTimeOptions = DEFAULT_DATE_TIME_OPTIONS) => {
if (!value) return "—";
const date = value instanceof Date ? value : new Date(value);
if (Number.isNaN(date.getTime())) return "—";
return new Intl.DateTimeFormat("ru-RU", {
...options,
timeZone: browserTimeZone.value ?? "UTC"
}).format(date);
};
return {
browserTimeZone,
formatDateTime
};
}