mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
add canonicalizeTimezone conversions
Co-authored-by: Om Mishra <contact@om-mishra.com>
This commit is contained in:
parent
49e1582c28
commit
839bf3898f
3 changed files with 36 additions and 4 deletions
|
|
@ -5,7 +5,7 @@ export function useDateParameters() {
|
|||
const {
|
||||
dateRange: { startDate, endDate, unit },
|
||||
} = useDateRange();
|
||||
const { timezone, toUtc } = useTimezone();
|
||||
const { timezone, toUtc, canonicalizeTimezone } = useTimezone();
|
||||
|
||||
return {
|
||||
startAt: +toUtc(startDate),
|
||||
|
|
@ -13,6 +13,6 @@ export function useDateParameters() {
|
|||
startDate: toUtc(startDate).toISOString(),
|
||||
endDate: toUtc(endDate).toISOString(),
|
||||
unit,
|
||||
timezone,
|
||||
timezone: canonicalizeTimezone(timezone),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { setItem } from '@/lib/storage';
|
||||
import { TIMEZONE_CONFIG } from '@/lib/constants';
|
||||
import { TIMEZONE_CONFIG, TIMEZONE_LEGACY } from '@/lib/constants';
|
||||
import { formatInTimeZone, zonedTimeToUtc, utcToZonedTime } from 'date-fns-tz';
|
||||
import { useApp, setTimezone } from '@/store/app';
|
||||
import { useLocale } from './useLocale';
|
||||
|
|
@ -34,5 +34,16 @@ export function useTimezone() {
|
|||
return utcToZonedTime(date, timezone);
|
||||
};
|
||||
|
||||
return { timezone, saveTimezone, formatTimezoneDate, toUtc, fromUtc };
|
||||
const canonicalizeTimezone = (timezone: string): string => {
|
||||
return TIMEZONE_LEGACY[timezone] ?? timezone;
|
||||
};
|
||||
|
||||
return {
|
||||
timezone,
|
||||
saveTimezone,
|
||||
formatTimezoneDate,
|
||||
toUtc,
|
||||
fromUtc,
|
||||
canonicalizeTimezone,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue