(logs)
| 12088 | |
| 12089 | const parts = []; |
| 12090 | for (const unit of units) { |
| 12091 | if (remaining >= unit.value || (unit.label === 's' && parts.length === 0)) { |
| 12092 | const amount = Math.floor(remaining / unit.value); |
| 12093 | if (amount > 0 || unit.label === 's') { |
| 12094 | parts.push(`${amount}${unit.label}`); |
| 12095 | } |
| 12096 | remaining -= amount * unit.value; |
| 12097 | } |
| 12098 | if (parts.length >= 2) { |
| 12099 | break; |
| 12100 | } |
| 12101 | } |
| 12102 | |
| 12103 | return parts.length > 0 ? parts.join(' ') : '0s'; |
| 12104 | } |
| 12105 | |
| 12106 | function buildLastSyncDisplay(stats) { |
| 12107 | if (!stats) { |
| 12108 | return 'Sync pending…'; |
| 12109 | } |
| 12110 | |
| 12111 | const ageSeconds = toNumber(stats.last_sync_age_seconds, NaN); |
| 12112 | const hasAge = Number.isFinite(ageSeconds); |
| 12113 | const relative = hasAge ? `${formatRelativeTime(ageSeconds)} ago` : ''; |
| 12114 | |
| 12115 | let timestampSource = stats.last_sync_iso ?? stats.last_sync_time ?? stats.last_sync_timestamp; |
| 12116 | let isoValue = null; |
| 12117 | |
| 12118 | if (typeof timestampSource === 'number') { |
| 12119 | isoValue = new Date(timestampSource * 1000).toISOString(); |
| 12120 | } else if (typeof timestampSource === 'string' && timestampSource) { |
| 12121 | isoValue = timestampSource; |
| 12122 | } |
| 12123 | |
| 12124 | let absolute = ''; |
| 12125 | if (isoValue) { |
| 12126 | const parsed = new Date(isoValue); |
| 12127 | if (!Number.isNaN(parsed.getTime())) { |
| 12128 | absolute = parsed.toLocaleString(); |
| 12129 | } |
| 12130 | } |
| 12131 | |
| 12132 | if (relative && absolute) { |
| 12133 | return `${relative} (${absolute})`; |
| 12134 | } |
| 12135 | |
| 12136 | if (relative) { |
| 12137 | return relative; |
| 12138 | } |
| 12139 | |
| 12140 | if (absolute) { |
| 12141 | return absolute; |
| 12142 | } |
| 12143 | |
| 12144 | return 'Sync pending…'; |
| 12145 | } |
| 12146 | |
| 12147 | function updateDashboardStats(stats) { |
no test coverage detected