mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 08:23:55 +00:00
24 lines
518 B
TypeScript
24 lines
518 B
TypeScript
import { MaybeNumber } from 'ontime-types';
|
|
|
|
import { clamp } from './math';
|
|
|
|
/**
|
|
* Returns completion percentage of a progress bar
|
|
* This code assumes the current time and duration have addedTime already applied
|
|
*/
|
|
export function getProgress(current: MaybeNumber, duration: MaybeNumber) {
|
|
if (current === null || duration === null) {
|
|
return 0;
|
|
}
|
|
|
|
if (current <= 0) {
|
|
return 100;
|
|
}
|
|
|
|
if (current >= duration) {
|
|
return 0;
|
|
}
|
|
|
|
return clamp(((duration - current) / duration) * 100, 0, 100);
|
|
}
|