-
Notifications
You must be signed in to change notification settings - Fork 158
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
background on why there is only one Duration type? #2915
Comments
IIRC the single duration type decision was made before I started working on Temporal in 2020, so I can't speak to the specifics at the time. @ptomato may remember more. But "we can't have a bigger API because of environment constraints" was NOT the reason; those concerns only cropped up in 2024. That said, there are a few significant advantages of having a single duration type:
The Temporal
There may be more pros and cons, but I think I covered the main ones above. Other Temporal champions may have more to add. If you do get a lot of pushback for a single Duration type, one compromise position you may want to consider is to also (or instead of Duration?) offer separate methods, e.g. |
Thank you for that answer! As a follow-up question, is there prior art on Temporal's |
I don't think so, I suspect for exactly the reason we discussed above: no project previously had the people time, calendar time, and inclination to find and solve the edge cases and other complexity involved in a Temporal-like |
You can see some investigation that I did into prior art here. |
Thank you, I had missed that. That's very helpful. |
Looks like this discussion has concluded, so I'll close the issue. For posterity, I'll also link to what I wrote in #2768 (comment):
|
Hiya!
I've non-exhaustively searched the issue tracker and the meeting minutes, but I haven't been able to find something that explains why there is only one Duration type. I suppose it might also explain why alternative designs were not chosen, with the leading contender perhaps being two duration types, where one is a "calendar" duration (containing potentially non-uniform units) and the other is an "absolute" duration (containing only uniform units).
java.time
, for example, hasPeriod
andDuration
types for these purposes, respectively. I believe NodaTime has a similar design.I've copied Temporal's design (one duration type) in my yet-to-be-released Rust datetime library that is heavily inspired by Temporal, and it's getting some push back among folks for which I've asked to review the API. To me, the design makes a lot of sense. It seems simpler. Being able to go back-and-forth between calendar and clock/absolute units is great. And I think it all works because Temporal gets the edge cases right. Like, when you're using a
ZonedDateTime
, there is no way to abuse the API such that 1 day isn't interpreted correctly. (The only way I can think of is if the user themselves writes "24 hours" thinking it will be 1 day, but I don't see how to prevent that from happening in any design.)So I guess, does there exist something written down that goes through the trade offs? What kinds of things are worse in a world with one duration type? What kinds of things are better? And why did y'all ultimately land on one type? Is it because of a conceptual calculation in terms of what would be best for users? Or was there more of a "we can't have a bigger API because of environment constraints" decision going on? (Like the in-progress removals of custom time zones and calendars.)
Thanks!
The text was updated successfully, but these errors were encountered: