mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Render UTC dates in sessions.
This commit is contained in:
parent
c79720ae1d
commit
deb9dd60df
10 changed files with 35 additions and 62 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { setItem } from 'next-basics';
|
||||
import { TIMEZONE_CONFIG } from 'lib/constants';
|
||||
import { formatInTimeZone } from 'date-fns-tz';
|
||||
import { formatInTimeZone, zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';
|
||||
import useStore, { setTimezone } from 'store/app';
|
||||
|
||||
const selector = (state: { timezone: string }) => state.timezone;
|
||||
|
|
@ -23,7 +23,15 @@ export function useTimezone() {
|
|||
);
|
||||
};
|
||||
|
||||
return { timezone, saveTimezone, formatDate };
|
||||
const toUtc = (date: Date | string | number) => {
|
||||
return zonedTimeToUtc(date, timezone);
|
||||
};
|
||||
|
||||
const fromUtc = (date: Date | string | number) => {
|
||||
return utcToZonedTime(date, timezone);
|
||||
};
|
||||
|
||||
return { timezone, saveTimezone, formatDate, toUtc, fromUtc };
|
||||
}
|
||||
|
||||
export default useTimezone;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue