Skip to content

Commit c4e7c4e

Browse files
committed
Enhance LSG sample client T-Timer display with state debugging
- Add formatTimestampToTimeOfDay() to display timestamps in HH:MM:SS format - Show timer state context: (paused), (pauseTime: HH:MM:SS), or (zeroTime: HH:MM:SS) - Factor in pauseTime when calculating timer display values to freeze countdown correctly - Apply same logic to both current and projected timer states
1 parent 14ce21e commit c4e7c4e

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

  • packages/live-status-gateway/sample-client

packages/live-status-gateway/sample-client/script.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ function formatMillisecondsToTime(milliseconds) {
187187
return `${isNegative ? '+' : ''}${formattedHours}:${formattedMinutes}:${formattedSeconds}`
188188
}
189189

190+
function formatTimestampToTimeOfDay(timestamp) {
191+
const date = new Date(timestamp)
192+
const hours = String(date.getHours()).padStart(2, '0')
193+
const minutes = String(date.getMinutes()).padStart(2, '0')
194+
const seconds = String(date.getSeconds()).padStart(2, '0')
195+
return `${hours}:${minutes}:${seconds}`
196+
}
197+
190198
function handleTTimers(tTimers) {
191199
const tTimersDiv = document.getElementById(T_TIMERS_DIV_ID)
192200
if (!tTimersDiv || !tTimers) return
@@ -255,33 +263,38 @@ function updateTTimers(tTimers) {
255263
let currentTime
256264
if (timer.state.paused) {
257265
currentTime = timer.state.duration
266+
valueSpan.textContent = formatMillisecondsToTime(currentTime) + ' (paused)'
258267
} else if (timer.state.pauseTime && now >= timer.state.pauseTime) {
259268
// Timer has reached its pauseTime - freeze at that moment
260269
currentTime = timer.state.zeroTime - timer.state.pauseTime
270+
valueSpan.textContent = formatMillisecondsToTime(currentTime) + ` (pauseTime: ${formatTimestampToTimeOfDay(timer.state.pauseTime)})`
261271
} else {
262272
currentTime = timer.state.zeroTime - now
273+
valueSpan.textContent = formatMillisecondsToTime(currentTime) + ` (zeroTime: ${formatTimestampToTimeOfDay(timer.state.zeroTime)})`
263274
}
264275

265-
valueSpan.textContent = formatMillisecondsToTime(currentTime)
266-
267276
// Update projected time if available
268277
const projectedLi = document.getElementById(`t-timer-projected-${timer.index}`)
269278
if (projectedLi && timer.projected) {
270279
let projectedTime
280+
let projectedInfo = ''
271281
if (timer.projected.paused) {
272282
projectedTime = timer.projected.duration
283+
projectedInfo = ' (paused)'
273284
} else if (timer.projected.pauseTime && now >= timer.projected.pauseTime) {
274285
// Projected timer has reached its pauseTime - freeze at that moment
275286
projectedTime = timer.projected.zeroTime - timer.projected.pauseTime
287+
projectedInfo = ` (pauseTime: ${formatTimestampToTimeOfDay(timer.projected.pauseTime)})`
276288
} else {
277289
projectedTime = timer.projected.zeroTime - now
290+
projectedInfo = ` (zeroTime: ${formatTimestampToTimeOfDay(timer.projected.zeroTime)})`
278291
}
279292

280293
const diff = currentTime - projectedTime
281294
const diffStr = formatMillisecondsToTime(Math.abs(diff))
282295
const status = diff > 0 ? 'under' : 'over'
283296

284-
projectedLi.textContent = `Projected: ${formatMillisecondsToTime(projectedTime)} (${diffStr} ${status})`
297+
projectedLi.textContent = `Projected: ${formatMillisecondsToTime(projectedTime)}${projectedInfo} (${diffStr} ${status})`
285298
}
286299
})
287300
}

0 commit comments

Comments
 (0)