Skip to content

fix: correct duration formatting for periods longer than 24 hours#20412

Open
aaron-he-zhu wants to merge 2 commits intoanomalyco:devfrom
aaron-he-zhu:fix/util-duration-day-calculation
Open

fix: correct duration formatting for periods longer than 24 hours#20412
aaron-he-zhu wants to merge 2 commits intoanomalyco:devfrom
aaron-he-zhu:fix/util-duration-day-calculation

Conversation

@aaron-he-zhu
Copy link
Copy Markdown

Issue for this PR

Closes #20407

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Locale.duration() had days and hours swapped in its calculation for inputs >= 24 hours. It computed total hours first, then derived days from the hour remainder, which always produced 0 days.

For example, 25 hours displayed as 0d 25h instead of 1d 1h.

Fixed by computing days first, then hours from the remainder. Also added unit tests for the Locale utility module.

How did you verify your code works?

Added unit tests covering all duration ranges (ms, seconds, minutes, hours, days). Tests pass with the fix applied:

  • duration(90000000) now returns "1d 1h" instead of "0d 25h"
  • duration(172800000) now returns "2d 0h" instead of "0d 48h"

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Aaron Zhu added 2 commits March 31, 2026 23:40
The duration() function had days and hours swapped in its calculation
for inputs >= 86400000ms. It computed hours first then took the
remainder for days, which always produced 0 days (since the hour
remainder is always less than one day in milliseconds).

For example, 25 hours displayed as "0d 25h" instead of "1d 1h".

Compute days first, then derive remaining hours from the remainder.
Add tests for duration(), number(), truncate(), and pluralize() in the
Locale utility module, covering edge cases including the day/hour
calculation fix.
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.

[BUG] Locale.duration() always shows 0 days for periods longer than 24 hours

1 participant