-
Notifications
You must be signed in to change notification settings - Fork 149
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
Suggestion: consistent balancing behavior for Duration's plus
and minus
methods
#645
Comments
|
Excerpting Shane's idea from #337 (comment):
Note that balancing from hours<->days like the examples above requires a time zone and starting |
With unsigned durations, addition is fundamentally a different operation than subtraction. Addition can only overflow to infinity, that is, if we make the change in #664 so that disambiguation doesn't apply to the edge of the representable range, then there's not even any use for disambiguation in Duration.plus. If we keep unsigned durations and the With signed durations, then I agree about making the behaviour of plus and minus consistent. |
Related feedback from @romulocintra in #772:
I assume he means |
I believe this is done in #811, actually? |
Yep. #811 should fix this issue. Specifically (from #782):
|
Duration.prototype.minus
supports balancing, butDuration.prototype.plus
doesn't. The docs admit that includingbalance
inminus
is not strictly required:Why does only
minus
get "convenience"? This inconsistency seems unnecessary and will makes things harder for new users. Seems like either both methods should balance, or neither of them should.One option would be to remove balancing from the options for all
Duration
methods (includingwith
andfrom
), and add a newbalanced
method to do the balancing. I think @sffc recommended adding this kind of method in another issue, but I can't find it at the moment.Another option would be to add a balance option to
plus
so that all fourDuration
methods would have consistent behavior.But I don't think that the current inconsistent state makes sense.
Note that if we provide negative durations (#558), then parallel behavior between
plus
andminus
will be required regardless.To illustrate the problem, here's a use-case: "adjust a meeting length by a signed number of minutes and return a balanced result"
Another challenge with the current behavior is that balancing for
plus
results is not discoverable via reading code or via IDE autocomplete.The text was updated successfully, but these errors were encountered: