Update useTimezone.ts

This commit is contained in:
Minseo Lee 2024-08-27 17:49:59 +09:00
parent 5d37810686
commit 474cba2182

View file

@ -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) => {