Skip to content

Commit

Permalink
feat: add hours in formatTime
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Feb 6, 2025
1 parent de58b22 commit c3e7537
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/components/ControlSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ export const ControlSlider = forwardRef<
accessibilityValue={{
min: 0,
max: totalDuration,
text: `${formatTime(timeValue.value)} of ${formatTime(
totalDuration
)}`,
text: `${timeValue.value}s of ${formatTime(totalDuration)}s`,
}}
accessibilityHint="Drag left or right to adjust the current time"
accessibilityActions={[
Expand Down
14 changes: 12 additions & 2 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export const formatTime = (time: number) => {
const minutes = Math.floor(time / 60);
const hours = Math.floor(time / 3600);
const minutes = Math.floor((time % 3600) / 60);
const seconds = Math.floor(time % 60);
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;

if (hours > 0) {
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds
.toString()
.padStart(2, '0')}`;
}

return `${minutes.toString().padStart(2, '0')}:${seconds
.toString()
.padStart(2, '0')}`;
};

0 comments on commit c3e7537

Please sign in to comment.