1 import { getSHA256String } from '@proton/shared/lib/helpers/crypto';
3 const DAY_IN_MILLISECONDS = 86400000;
4 const LOCALSTORAGE_TZ_KEY = 'tzSuggestion';
6 export const getTimezoneSuggestionKey = async (userID: string) => {
7 return getSHA256String(`${LOCALSTORAGE_TZ_KEY}${userID}`);
10 export const getLastTimezoneSuggestion = (key: string) => {
11 const defaultDate = new Date(2000, 0, 1);
13 const lastSuggestion = parseInt(`${window.localStorage.getItem(key)}`, 10);
14 const date = new Date(lastSuggestion);
15 if (Number.isNaN(+date)) {
24 export const saveLastTimezoneSuggestion = (key: string) => {
26 const timestamp = +new Date();
27 window.localStorage.setItem(key, `${timestamp}`);
28 // eslint-disable-next-line no-empty
32 export const canAskTimezoneSuggestion = (key: string) => {
33 return Date.now() - +getLastTimezoneSuggestion(key) >= DAY_IN_MILLISECONDS;