mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 20:45:39 +01:00
Update useTimezone.ts
This commit is contained in:
parent
5d37810686
commit
474cba2182
1 changed files with 4 additions and 9 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import { setItem } from 'next-basics';
|
import { setItem } from 'next-basics';
|
||||||
import { TIMEZONE_CONFIG } from 'lib/constants';
|
import { TIMEZONE_CONFIG } from 'lib/constants';
|
||||||
import { formatInTimeZone, zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';
|
import { zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';
|
||||||
import useStore, { setTimezone } from 'store/app';
|
import useStore, { setTimezone } from 'store/app';
|
||||||
|
import type { FormatDateOptions, IntlShape } from 'react-intl';
|
||||||
|
|
||||||
const selector = (state: { timezone: string }) => state.timezone;
|
const selector = (state: { timezone: string }) => state.timezone;
|
||||||
|
|
||||||
|
|
@ -13,14 +14,8 @@ export function useTimezone() {
|
||||||
setTimezone(value);
|
setTimezone(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatTimezoneDate = (date: string, pattern: string) => {
|
const formatTimezoneDate = (intl: IntlShape, date: string, options?: FormatDateOptions) => {
|
||||||
return formatInTimeZone(
|
return intl.formatDate(date, options);
|
||||||
/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{3})?Z$/.test(date)
|
|
||||||
? date
|
|
||||||
: date.split(' ').join('T') + 'Z',
|
|
||||||
timezone,
|
|
||||||
pattern,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const toUtc = (date: Date | string | number) => {
|
const toUtc = (date: Date | string | number) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue