Skip to content

Bug: Locale.duration displays wrong days/hours for durations ≥24h #368

@anandgupta42

Description

@anandgupta42

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:

  • hours computes total hours (e.g., 25 for 90000000ms) instead of the remainder after extracting days
  • days 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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions