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/client/hooks/useFormatTime.js

22 lines
636 B

import { useCallback } from 'react';
import moment from 'moment';
import { useUserPreference } from '../contexts/UserContext';
import { useSetting } from '../contexts/SettingsContext';
const dayFormat = ['h:mm A', 'H:mm'];
export const useFormatTime = () => {
const clockMode = useUserPreference('clockMode', false);
const format = useSetting('Message_TimeFormat');
const sameDay = dayFormat[clockMode - 1] || format;
return useCallback((time) => {
switch (clockMode) {
case 1:
case 2:
return moment(time).format(sameDay);
default:
return moment(time).format(format);
}
}, [clockMode, format, sameDay]);
};