( expiresAt: string, now: number = Date.now(), )
| 1 | // "17h", "45m", "1m": how long a room has, as its header says it. |
| 2 | export 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. |
no test coverage detected