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):
consthours=Math.floor(input/3600000)constdays=Math.floor((input%3600000)/86400000)return`${days}d ${hours}h`Problem:
hours computes total hours (e.g., 25 for 90000000ms) instead of the remainder after extracting daysdays uses input % 3600000 (remainder after hours), then divides by 86400000 — this always yields 0 because 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:
constdays=Math.floor(input/86400000)consthours=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.
Description
Locale.duration()inpackages/opencode/src/util/locale.tshas a bug in the>=24hbranch where the days and hours calculations are swapped.Current code (line ~57-59):
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 dayExample:
Locale.duration(90000000)(25 hours = 1 day 1 hour)"1d 1h""0d 25h"Fix:
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
Test
A skipped test has been added in
packages/opencode/test/util/locale.test.tsthat documents the correct expected behavior. Unskip it after fixing.