Skip to content

fix(timer): round duration before splitting off minutes - #14246

Merged
robbyrussell merged 1 commit into
ohmyzsh:masterfrom
b84330808:fix-timer-rounding
Nov 6, 2026
Merged

robbyrussell merged 1 commit into
ohmyzsh:masterfrom
b84330808:fix-timer-rounding

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Standards checklist:

  • The PR title is descriptive.
  • The PR doesn't replicate another PR which is already open.
  • I have read the contribution guide and followed all the instructions.
  • The code follows the code style guide detailed in the wiki.
  • The code is mine or it's from somewhere with an MIT-compatible license.
  • If I used AI tools (ChatGPT, Claude, Gemini, etc.) to assist with this contribution, I've disclosed it below.
  • The code is efficient, to the best of my ability, and does not waste computer resources.
  • The code is stable and I have tested it myself, to the best of my abilities.
  • If the code introduces new aliases, I provide a valid use case for all plugin users down below.

Changes:

  • timer plugin: __timer_format_duration split off the minutes before rounding the seconds, so a duration just under a minute boundary was displayed as 60.0s, and longer ones as e.g. 1m60.0s. The duration is now rounded to the displayed precision first (as an integer count of precision units) and only then split into minutes and seconds, so 59.97 displays as 1m0.0s and 119.97 as 2m0.0s.
  • Added plugins/timer/tests/timer.test.zsh covering the boundary cases at precision 0, 1 and 2.

Other comments:

AI disclosure: this change was prepared with AI assistance (Claude Code). I reviewed the diff and ran the tests myself.

Testing: zsh -df plugins/timer/tests/timer.test.zsh — with the old implementation 6 of the 14 cases fail (the 60.0s / 1m60.0s ones), with this change all 14 pass.

`__timer_format_duration` split the duration into whole minutes and
then rounded the remaining seconds to `TIMER_PRECISION`, so durations
just under a minute boundary were shown as `60.0s` or `1m60.0s`
instead of `1m0.0s` or `2m0.0s`. Round the whole duration to the
displayed precision first and split it afterwards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ohmyzsh ohmyzsh Bot added this to Main project Nov 5, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Main project Nov 5, 2026

@robbyrussell robbyrussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first contribution to Oh My Zsh! The tests pass on macOS with zsh 5.9, and times near a minute boundary now print correctly (1m0.0s instead of 60.0s). Merging.

@robbyrussell
robbyrussell merged commit 59ff4d0 into ohmyzsh:master Nov 6, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to In Progress in Main project Nov 6, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Main project Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants