mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +00:00
refactor: update timers (#729)
* refactor: remove duplication * refactor: previous times * refactor: event patching
This commit is contained in:
@@ -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