Skip to content

duration: extract roundDuration helper and round consistently#51

Open
sahilsGit wants to merge 1 commit into
docker:mainfrom
sahilsGit:fix/6891-duration-rounding
Open

duration: extract roundDuration helper and round consistently#51
sahilsGit wants to merge 1 commit into
docker:mainfrom
sahilsGit:fix/6891-duration-rounding

Conversation

@sahilsGit
Copy link
Copy Markdown

Consolidates ad-hoc rounding (int(d.Hours()+0.5)) and integer truncation into a single roundDuration helper, so days/weeks/months/years all use round-half-up semantics. Adds day/week/month/year constants and extends tests.

Refs #6891

- What I did

Made HumanDuration round consistently across all units. Previously only the hours branch rounded; days/weeks/months/years truncated, so e.g. 2w4d reported "2 weeks" instead of the closer "3 weeks".

- How I did it

  • Added day/week/month/year constants.
  • Added roundDuration(d, unit) int using round-half-up.
  • Routed every branch through roundDuration and switched thresholds to duration-based comparisons (d < 2*week).
  • Updated tests with boundary cases and corrected 2w4d → "3 weeks".

- How to verify it

go test -run TestHumanDuration -v

Consolidates ad-hoc rounding (int(d.Hours()+0.5)) and integer truncation
into a single roundDuration helper, so days/weeks/months/years all use
round-half-up semantics. Adds day/week/month/year constants and extends
tests for the new rounding behavior.

Refs #6891

Signed-off-by: Sahil Singh <sahiilsiingh37@gmail.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants