The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/hooks/useTimezoneTime.ts

29 lines
628 B

import moment from 'moment';
import { useState, useEffect } from 'react';
import { useFormatTime } from './useFormatTime';
export const useTimezoneTime = (offset: number, interval = 1000): string => {
const [time, setTime] = useState<moment.Moment>(() => moment().utcOffset(offset));
const format = useFormatTime();
useEffect(() => {
if (offset === undefined) {
return;
}
const update = (): void => {
setTime(moment().utcOffset(offset));
};
const timer = setInterval(update, interval);
update();
return (): void => {
clearInterval(timer);
};
}, [offset, interval]);
return format(time);
};