add canonicalizeTimezone conversions

Co-authored-by: Om Mishra <contact@om-mishra.com>
This commit is contained in:
Francis Cao 2025-11-10 17:27:45 -08:00
parent 49e1582c28
commit 839bf3898f
3 changed files with 36 additions and 4 deletions

View file

@ -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),
};
}

View file

@ -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,
};
}