-
Notifications
You must be signed in to change notification settings - Fork 22k
Handle negative numbers in NumberToHumanSizeConverter
#49791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle negative numbers in NumberToHumanSizeConverter
#49791
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that some other test cases has lots of assertions, but I think that for this (and other added test case) just a few edge case assertions would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically just copied them from the positive number test cases. I've cut down the number of cases being tested to a few less.
6d92215 to
968c154
Compare
jonathanhefner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to fix this for the sake of mathematical purity, but, practically, what is the use case?
The only one I can think of is something rate related, e.g. "free space is decreasing at a rate of 1 GB per day" => "-1 GB / day". But I can't think of a time when I've actually seen something like that.
activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb
Outdated
Show resolved
Hide resolved
968c154 to
c6dcb11
Compare
In my application I have code like this in order to display the size difference between two files. One will either be larger or smaller in comparision to another. number_to_human_size(entry.post_size - submission_file.size, precision: 2)Currently I have the method monkey-patched to work around this issue. |
Ah, yes, that's a good one! Thank you, @Earlopain! 💾 |
Handle negative numbers in `NumberToHumanSizeConverter`
Handle negative numbers in `NumberToHumanSizeConverter` (cherry picked from commit 87609e8)
Motivation / Background
This Pull Request has been created because
number_to_human_sizedoesn't handle negative numbers.Detail
number_to_humanalready supports negative numbers, this aligns the two methods.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]