-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
Locale.duration() in packages/opencode/src/util/locale.ts has a bug in the >=24h branch where the days and hours calculations are swapped.
Current code (line ~57-59):
const hours = Math.floor(input / 3600000)
const days = Math.floor((input % 3600000) / 86400000)
return `${days}d ${hours}h`Problem:
hourscomputes total hours (e.g., 25 for 90000000ms) instead of the remainder after extracting daysdaysusesinput % 3600000(remainder after hours), then divides by86400000— this always yields0because the remainder is always less than one hour, which is always less than one day
Example: Locale.duration(90000000) (25 hours = 1 day 1 hour)
- Expected:
"1d 1h" - Actual:
"0d 25h"
Fix:
const days = Math.floor(input / 86400000)
const hours = Math.floor((input % 86400000) / 3600000)
return `${days}d ${hours}h`Impact
This affects session duration display in the TUI for any session lasting longer than 24 hours. The duration shows as "0d Xh" with an ever-growing hour count instead of properly splitting into days and hours.
Reproduction
import { Locale } from "./src/util/locale"
console.log(Locale.duration(90000000)) // "0d 25h" — should be "1d 1h"
console.log(Locale.duration(172800000)) // "0d 48h" — should be "2d 0h"Test
A skipped test has been added in packages/opencode/test/util/locale.test.ts that documents the correct expected behavior. Unskip it after fixing.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working