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.ts

27 lines
739 B

import moment from 'moment';
import { useCallback } from 'react';
import { useSetting } from '../contexts/SettingsContext';
import { useUserPreference } from '../contexts/UserContext';
const dayFormat = ['h:mm A', 'H:mm'] as const;
export const useFormatTime = (): ((input: moment.MomentInput) => string) => {
const clockMode = useUserPreference<1 | 2>('clockMode');
const format = useSetting('Message_TimeFormat') as string;
const sameDay = clockMode !== undefined ? 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],
);
};