#35443 closed Bug (fixed)
Fix negative numbers for ordinals
Reported by: | Siburg | Owned by: | S-Tornqvist, Crustum7 |
---|---|---|---|
Component: | contrib.humanize | Version: | dev |
Severity: | Normal | Keywords: | humanize ordinal |
Cc: | Siburg, Martin Jonson | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The ordinal
template tag in /contrib/humanize/templatetags/humanize.py
returns strange results for negative numbers. For example:
-1 becomes -1th
-9 becomes -9st
-8 becomes -8nd
-7 becomes -7rd
I think that can be regarded as a bug. I can think of following approaches for dealing with it.
0) The null option. Won't fix. Assume ordinals are not supposed to support negative numbers. I can live with that; I don't have a use case for them either. I only discovered this anomaly while running a unit test with a -1 input. But it does feel weird to knowingly have this issue.
1) Treat it as invalid input and just return the original input; similar to a ValueError
.
2) Treat it as a positive number, and return the ordinal for its absolute value.
3) Treat it as valid input, and return the ordinal for its absolute value with a minus sign in front of it. I assume that will work for non-English languages too.
I suggest doing 3). Either way, if a decision or recommendation is made to do anything about it I can prepare a PR.
Change History (7)
comment:1 by , 6 months ago
Summary: | Support negative numbers for ordinals → Fix negative numbers for ordinals |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 6 months ago
Cc: | added |
---|---|
Has patch: | set |
comment:4 by , 6 months ago
Patch needs improvement: | set |
---|
comment:5 by , 5 months ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Version: | 5.0 → dev |
I think option 1 with a tweak to the docs, I don't think saying -2nd makes sense to support