|
|
|
|
|
by burntsushi
703 days ago
|
|
This is correct. You can't do a `span1 + span2`. You'd have to use `span1.checked_add(span2)`. The main problem I had with overloading `+` for span addition is that, in order to add two spans with non-uniform units (like years and months), you need a relative datetime. So `+` would effectively have to panic if you did `1.year() + 2.months()`, which seems like a horrific footgun. It would be plausible to make `+` for spans do _only_ component wise addition, but this would be an extremely subtle distinction between `+` and `Span::checked_add`. To the point where sometimes `+` and `checked_add` would agree on the results and sometimes they wouldn't. I think that would also be bad. So I started conservative for the time being: no `+` for adding spans together. |
|
I'm thinking something along the lines of how ActiveSupport::Duration works:
Of course the downside being that it would need to be sized large enough to contain each component, even though they may be rarely used.