Created formatDate function for rendering dates in correct timezone.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user