-
Notifications
You must be signed in to change notification settings - Fork 143
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
Ergonomic issues with Duration::add()
balancing
#2818
Comments
The first part ("Week Preservation") is no longer relevant because we're limiting the Duration adding to days. The second part ("LargestUnit for time parts? Balancing up?") is still relevant and I did some digging as to why there's no #645 I still need to identify precise individual comments. |
I can't figure out when Duration.p.add/subtract (formerly plus/minus) had its largestUnit parameter removed. Might be besides the point though: even if it still existed, I'd be questioning the ergonomics of the default I put in some more thought about how to make PT45M + PT45M yield a PT1H30M result, which I find more ergonomic than a PT90M result. Some options:
So, I'm okay closing this issue, leaving things as-is. The usecase I was originally concerned about was large lists of durations being summed (like total duration of events on a calendar), but people will likely do this more efficiently using integers of either days or nanoseconds. In other cases, users will just need to remember to calls Duration.p.round before displaying a duration that resulted from a Duration.p.round call. |
Sounds like we're thinking about scoping-down the functionality of
Duration::add()
. Here are some additional ergonomic issues with the current one. Maybe this will shape discussion. The two issues I bring up are concerned with the lack of smallestUnit/largestUnit.Week PreservationWeeks can be preserved during
Duration::round
if smallestUnit is set to 'week':However, if you're adding two durations that and either has a week AND either has year/month, there's no way to preserve weeks. This is because there's no notion of "smallestUnit" for
Duration::add()
.LargestUnit for time parts? Balancing up?
The above problem will go away if y/m/w/ units are disallowed, but here's a problem with time units:
Say you do two diff of two pairs of instants:
You'd need to know to use
Duration::round()
first before displaying to users if you want to maintainhour
precision.This happens because
Duration::add()
implicitly decides "largestUnit" by detecting the largest non-zero duration field.This is the only place in the API where something like "largestUnit" is data-dependent. I'd recommend always balancing-up smaller time units up to higher time units.
I'm still not sure whether hours should balance-up up to days or not.
The text was updated successfully, but these errors were encountered: