fix: correct duration formatting for periods longer than 24 hours#20412
Open
aaron-he-zhu wants to merge 2 commits intoanomalyco:devfrom
Open
fix: correct duration formatting for periods longer than 24 hours#20412aaron-he-zhu wants to merge 2 commits intoanomalyco:devfrom
aaron-he-zhu wants to merge 2 commits intoanomalyco:devfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #20407
Type of change
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 25hinstead of1d 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