(timestamp, now = new Date())
| 115 | return `${text.slice(0, Math.max(0, max - 3))}...`; |
| 116 | } |
| 117 | |
| 118 | function relativeTime(timestamp, now = new Date()) { |
| 119 | if (!timestamp) return 'unknown'; |
| 120 | const date = timestamp instanceof Date ? timestamp : new Date(timestamp); |
| 121 | if (Number.isNaN(date.getTime())) return String(timestamp); |
| 122 | |
| 123 | const diffMs = Math.max(0, now.getTime() - date.getTime()); |
| 124 | const diffSec = Math.floor(diffMs / 1000); |
| 125 | if (diffSec < 60) return 'just now'; |
| 126 | const diffMin = Math.floor(diffSec / 60); |
| 127 | if (diffMin < 60) return `${diffMin} min ago`; |
| 128 | const diffHr = Math.floor(diffMin / 60); |
| 129 | if (diffHr < 24) return `${diffHr} hr ago`; |
| 130 | const diffDays = Math.floor(diffHr / 24); |
| 131 | return `${diffDays} day${diffDays === 1 ? '' : 's'} ago`; |
| 132 | } |
| 133 | |
| 134 | function extractDirection(content) { |
no outgoing calls
no test coverage detected