1- /* eslint-disable @typescript-eslint/explicit-function-return-type */
21import { Tag } from '@rocket.chat/fuselage' ;
32import type * as MessageParser from '@rocket.chat/message-parser' ;
4- import { format } from 'date-fns' ;
5- import { useContext , useEffect , useState , type ReactElement } from 'react' ;
3+ import { format , intlFormatDistance } from 'date-fns' ;
4+ import { useContext , useEffect , useState } from 'react' ;
65import { ErrorBoundary } from 'react-error-boundary' ;
76
8- import { timeAgo } from './timeago' ;
97import { MarkupInteractionContext } from '../../MarkupInteractionContext' ;
108
119type BoldSpanProps = {
1210 children : MessageParser . Timestamp ;
1311} ;
1412
15- const Timestamp = ( { format, value } : { format : 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' ; value : Date } ) : ReactElement => {
13+ const Timestamp = ( { format, value } : { format : 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' ; value : Date } ) => {
1614 switch ( format ) {
1715 case 't' : // Short time format
1816 return < ShortTime value = { value } /> ;
@@ -37,7 +35,7 @@ const Timestamp = ({ format, value }: { format: 't' | 'T' | 'd' | 'D' | 'f' | 'F
3735} ;
3836
3937// eslint-disable-next-line react/no-multi-comp
40- const TimestampWrapper = ( { children } : BoldSpanProps ) : ReactElement => {
38+ const TimestampWrapper = ( { children } : BoldSpanProps ) => {
4139 const { enableTimestamp } = useContext ( MarkupInteractionContext ) ;
4240
4341 if ( ! enableTimestamp ) {
@@ -87,12 +85,12 @@ const RelativeTime = ({ value }: { value: Date }) => {
8785 const time = value . getTime ( ) ;
8886
8987 const { language } = useContext ( MarkupInteractionContext ) ;
90- const [ text , setTime ] = useState ( ( ) => timeAgo ( time , language ?? 'en' ) ) ;
88+ const [ text , setTime ] = useState ( ( ) => intlFormatDistance ( time , Date . now ( ) , { locale : language ?? 'en' } ) ) ;
9189 const [ timeToRefresh , setTimeToRefresh ] = useState ( ( ) => getTimeToRefresh ( time ) ) ;
9290
9391 useEffect ( ( ) => {
9492 const interval = setInterval ( ( ) => {
95- setTime ( timeAgo ( value . getTime ( ) , 'en' ) ) ;
93+ setTime ( intlFormatDistance ( value . getTime ( ) , Date . now ( ) , { locale : 'en' } ) ) ;
9694 setTimeToRefresh ( getTimeToRefresh ( time ) ) ;
9795 } , timeToRefresh ) ;
9896
0 commit comments