Fix pluralization when maxDecimalPoints truncates the count to 1 - #239
Closed
dualfroz wants to merge 1 commit into
Closed
Fix pluralization when maxDecimalPoints truncates the count to 1#239dualfroz wants to merge 1 commit into
maxDecimalPoints truncates the count to 1#239dualfroz wants to merge 1 commit into
Conversation
Owner
|
Thanks. I'll review in the next few weeks. |
When maxDecimalPoints truncates a unit count to exactly 1, the rendered
number showed 1 while the word was pluralized from the raw count (for
example humanizeDuration(1500, { maxDecimalPoints: 0 }) returned
"1 seconds"). Pluralize from the normalized count that is actually
displayed so the number and word agree.
dualfroz
force-pushed
the
dualfroz/fix-plural-with-maxdecimalpoints
branch
from
September 5, 2026 23:13
e4768de to
f21a996
Compare
Owner
|
I made some changes to this and merged it in 924c2a1. This has been released in Thank you! |
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.
Problem
When the
maxDecimalPointsoption truncates a unit count down to exactly1,the rendered number and the unit word disagree. The number is shown as
1butthe word is pluralized:
The bug is language-independent; any language whose unit word is a function of
the count is affected (for example German returns
"1 Sekunden"instead of"1 Sekunde").Root cause
humanize-duration.js, inrenderPiece.The displayed count is
normalizedUnitCount, computed frommaxDecimalPoints:but the unit word was pluralized from the raw, un-truncated
unitCount:So
1.5seconds withmaxDecimalPoints: 0renders the count as"1"(fromnormalizedUnitCount) whilelanguageWord(1.5)returns the plural form, giving"1 seconds".Fix
Pluralize based on the count that is actually rendered,
normalizedUnitCount:When
maxDecimalPointsis unset,normalizedUnitCount === unitCount, soexisting behavior is unchanged. The fix only affects cases where the option
truncates the count.
Test
Added a test to
test/humanizer.jscovering the truncated-to-one case, atruncated count that stays plural, and the same mechanism in German:
Counterfactual (revert the one-line fix in
renderPiece):