Skip to content

Commit 6bd8b20

Browse files
committed
feat(T-Timers): Add calculateTimerDuration helper function
Add calculateTimerDuration() function to calculate current timer duration from TimerState, handling all three cases: - Manually paused or already pushing - Auto-pause at overrun (pauseTime) - Running normally Clients can import and use: import { calculateTimerDuration } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist' const duration = calculateTimerDuration(timer.state, getCurrentTime())
1 parent bac92cc commit 6bd8b20

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/corelib/src/dataModel/RundownPlaylist.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ export type TimerState =
164164
pauseTime?: number | null
165165
}
166166

167+
/**
168+
* Calculate the current duration for a timer state.
169+
* Handles paused, auto-pause (pauseTime), and running states.
170+
*
171+
* @param state The timer state
172+
* @param now Current timestamp in milliseconds
173+
* @returns The current duration in milliseconds
174+
*/
175+
export function timerStateToDuration(state: TimerState, now: number): number {
176+
if (state.paused) {
177+
// Manually paused by user or already pushing/overrun
178+
return state.duration
179+
} else if (state.pauseTime && now >= state.pauseTime) {
180+
// Auto-pause at overrun (current part ended)
181+
return state.zeroTime - state.pauseTime
182+
} else {
183+
// Running normally
184+
return state.zeroTime - now
185+
}
186+
}
187+
167188
export type RundownTTimerIndex = 1 | 2 | 3
168189

169190
export interface RundownTTimer {

0 commit comments

Comments
 (0)