MCPcopy Create free account
hub / github.com/dailydotdev/apps / formatTimeLeft

Function formatTimeLeft

packages/shared/src/features/liveChat/timeLeft.ts:2–16  ·  view source on GitHub ↗
(
  expiresAt: string,
  now: number = Date.now(),
)

Source from the content-addressed store, hash-verified

1// "17h", "45m", "1m": how long a room has, as its header says it.
2export const formatTimeLeft = (
3 expiresAt: string,
4 now: number = Date.now(),
5): string => {
6 const left = new Date(expiresAt).getTime() - now;
7 if (left <= 0) {
8 return '0m';
9 }
10 const minutes = Math.ceil(left / (60 * 1000));
11 if (minutes < 60) {
12 return `${minutes}m`;
13 }
14
15 return `${Math.round(minutes / 60)}h`;
16};
17
18// Fewer people than this is not a crowd worth announcing; the count stays
19// off until it works for the room.

Callers 4

timeLeft.spec.tsFile · 0.90
LiveChatHighlightCardRowFunction · 0.90
LiveChatPanelFunction · 0.90
formatEndsInFunction · 0.70

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected