Skip to content

In WebUI show pretty durations as hours and minutes via Intl.DurationFormat - #7530

Merged
6543 merged 5 commits into
woodpecker-ci:mainfrom
kevin9327:fix/pretty-duration-rounding
Nov 10, 2026
Merged

6543 merged 5 commits into
woodpecker-ci:mainfrom
kevin9327:fix/pretty-duration-rounding

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

prettyDuration picks its unit from the raw value and then rounds, so a duration just under a unit boundary is shown in the smaller unit with the boundary count:

prettyDuration(59_600)      // "60 seconds"  (expected "1 minute")
prettyDuration(3_576_000)   // "60 minutes"  (expected "1 hour")

This now also moves up a unit when the rounded count reaches it (Math.round(totalSeconds) >= 60, Math.round(totalMinutes) >= 60). Durations away from a boundary format exactly as before.

Test

New web/src/compositions/useDate.test.ts: unchanged output for ordinary durations, plus 59.6 s / 59.6 min (now "1 minute" / "1 hour") and 59.4 s / 59.4 min (still "59 seconds" / "59 minutes"). The rounding case fails on main (Received: "60 seconds") and passes with the fix. prettier -c and eslint --max-warnings 0 are clean on both files.

This change was prepared with AI assistance; I reviewed it and ran the test above locally.

59.6 seconds read "60 seconds" and 59.6 minutes "60 minutes"; pick the
larger unit once the rounded count reaches it.
@6543 6543 changed the title fix(web): move prettyDuration to the next unit when rounding reaches it In WebUI format duration to next unit when rounding reaches it Nov 10, 2026
@6543 6543 added ui frontend related enhancement improve existing features labels Nov 10, 2026
@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

I think 1h30min should be displayed as such ... the carrence can be 5min ...

@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

also what about using browser api Intl.DurationFormat ?

@6543
6543 self-requested a review November 10, 2026 18:33
@kevin9327

Copy link
Copy Markdown
Contributor Author

Thanks, both good points. Pushed a follow-up:

  • prettyDuration now uses Intl.DurationFormat (style long), so locale wording and list joining come from the browser.
  • From one hour on it shows hours and minutes, with minutes rounded to 5: 90 min reads "1 hour, 30 minutes", 93 min reads "1 hour, 35 minutes", 118 min reads "2 hours".
  • Below an hour it stays one unit (seconds, then minutes), and the rounding fix from the first commit still holds (59.6 s reads "1 minute", 59.6 min reads "1 hour").
  • 0 s still reads "0 seconds" (secondsDisplay: 'always', since DurationFormat returns an empty string for an all-zero duration otherwise).

Intl.DurationFormat is in the TS es2025 lib and in Node 24, which web/package.json already requires. I ran the updated useDate.test.ts with vitest on Node 24 and type-checked the file with TS 6.0.3.

@kevin9327 kevin9327 changed the title In WebUI format duration to next unit when rounding reaches it In WebUI show pretty durations as hours and minutes via Intl.DurationFormat Nov 10, 2026
@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

well the 5min idea i did not formulated to well ...
-> 5a5b37e
was what i thought ...

@6543

6543 commented Nov 10, 2026

Copy link
Copy Markdown
Member

ahh ... i missed the <= 5min to next full hour...

@6543
6543 merged commit d068fcc into woodpecker-ci:main Nov 10, 2026
7 checks passed
@woodpecker-bot woodpecker-bot mentioned this pull request Nov 10, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features ui frontend related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants