diff --git a/src/components/hooks/useTimezone.ts b/src/components/hooks/useTimezone.ts index c74f513f5..f7976aabb 100644 --- a/src/components/hooks/useTimezone.ts +++ b/src/components/hooks/useTimezone.ts @@ -1,7 +1,8 @@ import { setItem } from 'next-basics'; 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 type { FormatDateOptions, IntlShape } from 'react-intl'; const selector = (state: { timezone: string }) => state.timezone; @@ -13,14 +14,8 @@ export function useTimezone() { setTimezone(value); }; - const formatTimezoneDate = (date: string, pattern: string) => { - return formatInTimeZone( - /^[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 formatTimezoneDate = (intl: IntlShape, date: string, options?: FormatDateOptions) => { + return intl.formatDate(date, options); }; const toUtc = (date: Date | string | number) => {