-
Notifications
You must be signed in to change notification settings - Fork 761
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
classlib: fix SimpleNumber asTimeString for negative values #4802
classlib: fix SimpleNumber asTimeString for negative values #4802
Conversation
handle negative values
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.
thanks! can you please add the following test cases:
-0.0.asTimeString
-1.asTimeString(dropDaysIfPossible: false)
decimal = number.asInteger; | ||
days = decimal.div(86400).min(maxDays); | ||
days = if(dropDaysIfPossible and: { days == 0 }) { | ||
days = "" | ||
} { | ||
days.asString.padLeft(3, "0").add($:); | ||
}; | ||
if(isNegative, {days = "-" ++ days}); |
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.
in general we use trailing closure for if
in the class library. i've added a style point for that here: https://github.com/supercollider/supercollider/wiki/Code-style-guidelines#trailing-closure-syntax
can you change this one here please?
var number, decimal, days, hours, minutes, seconds, mseconds, isNegative = false; | ||
if(this < 0, { | ||
isNegative = true; | ||
}); |
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.
this can be simplified to var number, decimal, days, hours, minutes, seconds, mseconds, isNegative = this < 0;
@dyfer gentle reminder to label your PRs! |
Sorry I missed it! And thanks! |
Thanks for a quick feedback! I changed the if statement in the code that I added, but did not touch the one that was there already, should I change that too? As for
I'm not sure what the proper output should be. Intuitively I'd expect -0.0.asTimeString;
-> -00:00:00.000 but since we don't seem to be able to differentiate between -0.0.asTimeString;
-> 00:00:00.000 In that case, should this be the expected result of the test? |
...I guess I could check for identity:
in the method, as a special case. Is this the way to go? edit: I added that check, let me know what you think, thanks! |
that one seems right already, not sure what you're asking
sorry, should have clarified. i think what it does now is fine, and actually makes more sense in my opinion as "-0" is not an intuitively sensible number for most people. this is also a lossy conversion so it's not vital to make sure everything round-trips between this and asSecs perfectly. i just want to pin that behavior so we can be aware if it changes in the future. |
My bad! I was in a rush and misread the code.
Sorry, wanted to be done with this and followed that identity path. So now should I revert it and leave the behavior of
? |
"-00:00:00.000".asSecs;
-> -0.0 so maybe that explicit check for |
took some time to think about this one. i don't think we should output a timestamp saying furthermore, the knowledge that the input value that produced another reason i prefer to not have a finally, in my experience the vast number of numerical comparisons are typically done with so, i think this PR should be modified such that |
Thanks @brianlheim for your thoughts. I changed this PR so it is now -0.0.asTimeString;
-> 00:00:00.000
AFAICT I only need to not check for identity, since -0.0 < 0;
-> false I'm just pointing it out to make sure I'm not doing something wrong. |
you also need to handle inputs like -.001 which are negative but may round up to 0 for the requested precision. please make sure to add a test for that. |
done! |
Purpose and Motivation
Negative
SimpleNumber -asTimeString
returned incorrect string.Previously:
Now:
Types of changes
To-do list