feat: introduce voice call dashboard (#14954)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
messageStamp,
|
||||
messageTimestamp,
|
||||
dynamicTime,
|
||||
dateFormat,
|
||||
shortTimestamp,
|
||||
dynamicTime,
|
||||
getDayDifferenceFromNow,
|
||||
hasOneDayPassed,
|
||||
messageStamp,
|
||||
messageTimestamp,
|
||||
relativeDayTimestamp,
|
||||
shortTimestamp,
|
||||
} from 'shared/helpers/timeHelper';
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -37,6 +38,33 @@ describe('#messageTimestamp', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#relativeDayTimestamp', () => {
|
||||
// System time is mocked to May 5, 2023 00:00 UTC.
|
||||
const toUnix = date => Math.floor(date / 1000);
|
||||
|
||||
it('returns the time for timestamps from today', () => {
|
||||
const today = toUnix(Date.UTC(2023, 4, 5, 15, 35, 0));
|
||||
expect(relativeDayTimestamp(today, 'Yesterday')).toEqual('3:35 PM');
|
||||
});
|
||||
|
||||
it('returns the supplied label for timestamps from yesterday', () => {
|
||||
const yesterday = toUnix(Date.UTC(2023, 4, 4, 9, 0, 0));
|
||||
expect(relativeDayTimestamp(yesterday, 'Yesterday')).toEqual('Yesterday');
|
||||
});
|
||||
|
||||
it('returns a day and month for older timestamps in the current year', () => {
|
||||
const earlierThisYear = toUnix(Date.UTC(2023, 1, 10, 12, 0, 0));
|
||||
expect(relativeDayTimestamp(earlierThisYear, 'Yesterday')).toEqual(
|
||||
'Feb 10'
|
||||
);
|
||||
});
|
||||
|
||||
it('returns a full date for timestamps from a previous year', () => {
|
||||
const lastYear = toUnix(Date.UTC(2021, 1, 10, 12, 0, 0));
|
||||
expect(relativeDayTimestamp(lastYear, 'Yesterday')).toEqual('Feb 10, 2021');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#dynamicTime', () => {
|
||||
it('returns correct value', () => {
|
||||
Date.now = vi.fn(() => new Date(Date.UTC(2023, 1, 14)).valueOf());
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
format,
|
||||
isSameYear,
|
||||
isThisYear,
|
||||
isToday,
|
||||
isYesterday,
|
||||
fromUnixTime,
|
||||
formatDistanceToNow,
|
||||
differenceInDays,
|
||||
@@ -33,6 +36,22 @@ export const messageTimestamp = (time, dateFormat = 'MMM d, yyyy') => {
|
||||
return messageDate;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats a Unix timestamp relative to today: the time for today, a caller-
|
||||
* supplied label for yesterday, and a date otherwise. The yesterday label is
|
||||
* passed in so the caller keeps ownership of translation.
|
||||
* @param {number} time - Unix timestamp.
|
||||
* @param {string} yesterdayLabel - Localized label shown for yesterday.
|
||||
* @returns {string} Formatted timestamp string.
|
||||
*/
|
||||
export const relativeDayTimestamp = (time, yesterdayLabel) => {
|
||||
const date = fromUnixTime(time);
|
||||
if (isToday(date)) return format(date, 'h:mm a');
|
||||
if (isYesterday(date)) return yesterdayLabel;
|
||||
if (isThisYear(date)) return format(date, 'MMM d');
|
||||
return format(date, 'MMM d, yyyy');
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a Unix timestamp to a relative time string (e.g., 3 hours ago).
|
||||
* @param {number} time - Unix timestamp.
|
||||
|
||||
Reference in New Issue
Block a user