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/lib/utils/timeAgo.ts

25 lines
923 B

import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import moment, { Moment, MomentInput } from 'moment';
import { settings } from '../../../app/settings/client';
import { t } from '../../../app/utils/client';
import { getUserPreference } from '../../../app/utils/lib/getUserPreference';
const dayFormat = ['h:mm A', 'H:mm'];
export const timeAgo = (date: MomentInput): string => {
const clockMode = Tracker.nonreactive(() => getUserPreference(Meteor.userId(), 'clockMode', false));
const messageTimeFormat = Tracker.nonreactive(() => settings.get('Message_TimeFormat'));
const sameDay = dayFormat[clockMode - 1] || messageTimeFormat;
return moment(date).calendar(null, {
lastDay: `[${t('yesterday')}]`,
sameDay,
lastWeek: 'dddd',
sameElse(this: Moment, now) {
const diff = Math.ceil(this.diff(now, 'years', true));
return diff < 0 ? 'MMM D YYYY' : 'MMM D';
},
});
};