2020-09-19 19:35:05 +02:00
|
|
|
import { useState, useCallback } from 'react';
|
|
|
|
import { getTimezone } from 'lib/date';
|
2022-08-29 05:20:54 +02:00
|
|
|
import { getItem, setItem } from 'next-basics';
|
2020-10-01 01:27:27 +02:00
|
|
|
import { TIMEZONE_CONFIG } from 'lib/constants';
|
2020-09-19 19:35:05 +02:00
|
|
|
|
2023-05-18 08:20:06 +02:00
|
|
|
export function useTimezone() {
|
2020-10-01 01:27:27 +02:00
|
|
|
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
|
2020-09-19 19:35:05 +02:00
|
|
|
|
|
|
|
const saveTimezone = useCallback(
|
|
|
|
value => {
|
2020-10-01 01:27:27 +02:00
|
|
|
setItem(TIMEZONE_CONFIG, value);
|
2020-09-19 19:35:05 +02:00
|
|
|
setTimezone(value);
|
|
|
|
},
|
|
|
|
[setTimezone],
|
|
|
|
);
|
|
|
|
|
|
|
|
return [timezone, saveTimezone];
|
|
|
|
}
|
2023-05-18 08:20:06 +02:00
|
|
|
|
|
|
|
export default useTimezone;
|