Skip to content

Commit

Permalink
refactor: improve time added display
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Dec 1, 2024
1 parent becca1c commit 5c572cb
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PropsWithChildren } from 'react';
import { Tooltip } from '@chakra-ui/react';
import { Playback, TimerPhase } from 'ontime-types';
import { dayInMs, millisToMinutes, millisToSeconds, millisToString } from 'ontime-utils';
import { dayInMs, millisToString } from 'ontime-utils';

import { useTimer } from '../../../../common/hooks/useSocket';
import { formatDuration } from '../../../../common/utils/time';
import TimerDisplay from '../timer-display/TimerDisplay';

import style from './PlaybackTimer.module.scss';
Expand All @@ -13,22 +14,12 @@ interface PlaybackTimerProps {
}

function resolveAddedTimeLabel(addedTime: number) {
function resolveClosestUnit(ms: number) {
if (ms < 6000) {
return `${millisToSeconds(ms)} seconds`;
} else if (ms < 12000) {
return '1 minute';
} else {
return `${millisToMinutes(ms)} minutes`;
}
}

if (addedTime > 0) {
return `Added ${resolveClosestUnit(addedTime)}`;
return `Added ${formatDuration(addedTime, false)}`;
}

if (addedTime < 0) {
return `Removed ${resolveClosestUnit(addedTime)}`;
return `Removed ${formatDuration(Math.abs(addedTime), false)}`;
}

return '';
Expand Down

0 comments on commit 5c572cb

Please sign in to comment.