Skip to content

Commit 2e53ea6

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 288cbfd commit 2e53ea6

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

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

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

Lines changed: 20 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,42 @@ 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 =
271+
formatMillisecondsToTime(currentTime) +
272+
` (pauseTime: ${formatTimestampToTimeOfDay(timer.state.pauseTime)})`
261273
} else {
262274
currentTime = timer.state.zeroTime - now
275+
valueSpan.textContent =
276+
formatMillisecondsToTime(currentTime) +
277+
` (zeroTime: ${formatTimestampToTimeOfDay(timer.state.zeroTime)})`
263278
}
264279

265-
valueSpan.textContent = formatMillisecondsToTime(currentTime)
266-
267280
// Update projected time if available
268281
const projectedLi = document.getElementById(`t-timer-projected-${timer.index}`)
269282
if (projectedLi && timer.projected) {
270283
let projectedTime
284+
let projectedInfo = ''
271285
if (timer.projected.paused) {
272286
projectedTime = timer.projected.duration
287+
projectedInfo = ' (paused)'
273288
} else if (timer.projected.pauseTime && now >= timer.projected.pauseTime) {
274289
// Projected timer has reached its pauseTime - freeze at that moment
275290
projectedTime = timer.projected.zeroTime - timer.projected.pauseTime
291+
projectedInfo = ` (pauseTime: ${formatTimestampToTimeOfDay(timer.projected.pauseTime)})`
276292
} else {
277293
projectedTime = timer.projected.zeroTime - now
294+
projectedInfo = ` (zeroTime: ${formatTimestampToTimeOfDay(timer.projected.zeroTime)})`
278295
}
279296

280297
const diff = currentTime - projectedTime
281298
const diffStr = formatMillisecondsToTime(Math.abs(diff))
282299
const status = diff > 0 ? 'under' : 'over'
283300

284-
projectedLi.textContent = `Projected: ${formatMillisecondsToTime(projectedTime)} (${diffStr} ${status})`
301+
projectedLi.textContent = `Projected: ${formatMillisecondsToTime(projectedTime)}${projectedInfo} (${diffStr} ${status})`
285302
}
286303
})
287304
}

0 commit comments

Comments
 (0)