mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-18 21:54:09 +00:00
refactor: update timers (#729)
* refactor: remove duplication * refactor: previous times * refactor: event patching
This commit is contained in:
@@ -8,7 +8,7 @@ export { calculateDuration } from './src/validate-events/validateEvent.js';
|
||||
export { sanitiseCue } from './src/cue-utils/cueUtils.js';
|
||||
export { getCueCandidate } from './src/cue-utils/cueUtils.js';
|
||||
export { generateId } from './src/generate-id/generateId.js';
|
||||
export { swapOntimeEvents } from './src/rundown-utils/rundownUtils.js';
|
||||
export { getPreviousEvent, swapOntimeEvents } from './src/rundown-utils/rundownUtils.js';
|
||||
|
||||
// format utils
|
||||
export {
|
||||
@@ -20,7 +20,13 @@ export {
|
||||
millisToSeconds,
|
||||
} from './src/date-utils/conversionUtils.js';
|
||||
export { isTimeString } from './src/date-utils/isTimeString.js';
|
||||
export { formatFromMillis, millisToString, removeLeadingZero, removeSeconds } from './src/date-utils/timeFormatting.js';
|
||||
export {
|
||||
formatFromMillis,
|
||||
millisToString,
|
||||
removeLeadingZero,
|
||||
removeSeconds,
|
||||
removeTrailingZero,
|
||||
} from './src/date-utils/timeFormatting.js';
|
||||
export { isColourHex } from './src/regex-utils/isColourHex.js';
|
||||
|
||||
// time utils
|
||||
|
||||
@@ -52,6 +52,17 @@ export function removeLeadingZero(timer: string): string {
|
||||
return timer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a string such as 00:10:10 and removes the seconds field if it is 00
|
||||
* @param timer
|
||||
*/
|
||||
export function removeTrailingZero(timer: string): string {
|
||||
if (timer.endsWith(':00')) {
|
||||
return timer.slice(0, -3);
|
||||
}
|
||||
return timer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a string such as 00:10:10 and removes the seconds field
|
||||
* @param timer
|
||||
|
||||
@@ -7,7 +7,7 @@ import { dayInMs } from '../timeConstants.js';
|
||||
* @param {EndAction} maybeAction
|
||||
* @param {EndAction} [fallback]
|
||||
*/
|
||||
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None) {
|
||||
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None): EndAction {
|
||||
return Object.values(EndAction).includes(maybeAction as EndAction) ? (maybeAction as EndAction) : fallback;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export function validateEndAction(maybeAction: unknown, fallback = EndAction.Non
|
||||
* @param {TimerType} maybeTimerType
|
||||
* @param {TimerType} [fallback]
|
||||
*/
|
||||
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown) {
|
||||
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown): TimerType {
|
||||
return Object.values(TimerType).includes(maybeTimerType as TimerType) ? (maybeTimerType as TimerType) : fallback;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,11 @@ function convertToInteger(value: unknown): number {
|
||||
* @param _end
|
||||
* @param _duration
|
||||
*/
|
||||
export function validateTimes(_start?: unknown, _end?: unknown, _duration?: unknown) {
|
||||
export function validateTimes(
|
||||
_start?: unknown,
|
||||
_end?: unknown,
|
||||
_duration?: unknown,
|
||||
): { timeStart: number; duration: number; timeEnd: number } {
|
||||
const timeStart = convertToInteger(_start);
|
||||
const timeEnd = convertToInteger(_end);
|
||||
const duration = convertToInteger(_duration);
|
||||
|
||||
Reference in New Issue
Block a user