mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-03 21:39:08 +00:00
refactor: simplify overview logic
This commit is contained in:
committed by
Carlos Valente
parent
3c7e061e51
commit
efd05bcc34
@@ -95,7 +95,7 @@ function TitlesOverview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function TimerOverview() {
|
function TimerOverview() {
|
||||||
const {current} = useTimer();
|
const { current } = useTimer();
|
||||||
|
|
||||||
const display = millisToString(current);
|
const display = millisToString(current);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { dayInMs } from 'ontime-utils';
|
||||||
|
|
||||||
|
import { calculateEndAndDaySpan } from '../overviewUtils';
|
||||||
|
|
||||||
|
describe('calculateEndAndDaySpan', () => {
|
||||||
|
it('should return [null, 0] when end is null', () => {
|
||||||
|
const result = calculateEndAndDaySpan(null);
|
||||||
|
expect(result).toEqual([null, 0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return [end, 0] when end is less than or equal to dayInMs', () => {
|
||||||
|
const end = dayInMs / 2;
|
||||||
|
const result = calculateEndAndDaySpan(end);
|
||||||
|
expect(result).toEqual([end, 0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return [end % dayInMs, Math.floor(end / dayInMs)] when end is greater than dayInMs', () => {
|
||||||
|
const end = dayInMs * 1.5;
|
||||||
|
const result = calculateEndAndDaySpan(end);
|
||||||
|
expect(result).toEqual([end % dayInMs, Math.floor(end / dayInMs)]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -13,20 +13,14 @@ export function formatedTime(time: MaybeNumber) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates a day span from a number range
|
* Calculates how long a time is and how many days it spans
|
||||||
* @param end
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
export function calculateEndAndDaySpan(end: MaybeNumber): [MaybeNumber, number] {
|
export function calculateEndAndDaySpan(end: MaybeNumber): [MaybeNumber, number] {
|
||||||
let maybeEnd = end;
|
if (end !== null && end > dayInMs) {
|
||||||
let maybeDaySpan = 0;
|
return [end % dayInMs, Math.floor(end / dayInMs)];
|
||||||
if (end !== null) {
|
|
||||||
if (end > dayInMs) {
|
|
||||||
maybeEnd = end % dayInMs;
|
|
||||||
maybeDaySpan = Math.floor(end / dayInMs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return [maybeEnd, maybeDaySpan];
|
|
||||||
|
return [end, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user