Skip to content

Commit db87e4c

Browse files
brandonkachenclaude
andcommitted
refactor: Extract time formatting utility
Extracts elapsed time formatting logic into a reusable utility function that handles seconds, minutes, and hours display. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b592aeb commit db87e4c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cli/src/components/elapsed-timer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
22
import { TextAttributes } from '@opentui/core'
33

44
import { useTheme } from '../hooks/use-theme'
5+
import { formatElapsedTime } from '../utils/format-elapsed-time'
56

67
interface ElapsedTimerProps {
78
startTime: number | null
@@ -54,7 +55,7 @@ export const ElapsedTimer = ({
5455

5556
return (
5657
<span fg={theme.secondary} attributes={attributes}>
57-
{elapsedSeconds}s{suffix}
58+
{formatElapsedTime(elapsedSeconds)}{suffix}
5859
</span>
5960
)
6061
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Format elapsed seconds into a human-readable string.
3+
* - Under 60 seconds: "Xs"
4+
* - 60-3599 seconds (1-59 minutes): "Xm"
5+
* - 3600+ seconds (1+ hours): "Xh"
6+
*/
7+
export const formatElapsedTime = (elapsedSeconds: number): string => {
8+
if (elapsedSeconds < 60) {
9+
return `${elapsedSeconds}s`
10+
}
11+
12+
if (elapsedSeconds < 3600) {
13+
const minutes = Math.floor(elapsedSeconds / 60)
14+
return `${minutes}m`
15+
}
16+
17+
const hours = Math.floor(elapsedSeconds / 3600)
18+
return `${hours}h`
19+
}

0 commit comments

Comments
 (0)