Created formatDate function for rendering dates in correct timezone.

This commit is contained in:
Mike Cao 2024-08-13 00:40:19 -07:00
parent b11b2e3524
commit 9b005e11c0
3 changed files with 12 additions and 19 deletions

View file

@ -1,5 +1,6 @@
import { setItem } from 'next-basics';
import { TIMEZONE_CONFIG } from 'lib/constants';
import { formatInTimeZone } from 'date-fns-tz';
import useStore, { setTimezone } from 'store/app';
const selector = (state: { timezone: string }) => state.timezone;
@ -12,7 +13,11 @@ export function useTimezone() {
setTimezone(value);
};
return { timezone, saveTimezone };
const formatDate = (date: string, pattern: string) => {
return formatInTimeZone(date.split(' ').join('T') + 'Z', timezone, pattern);
};
return { timezone, saveTimezone, formatDate };
}
export default useTimezone;