-
Notifications
You must be signed in to change notification settings - Fork 156
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
Negative durations vs. order of operations #913
Comments
OK, now I'm confused. It seems that reversing the order-of-operations doesn't actually enable reversible behavior, at least in some cases. Example: Temporal.Date.from('2020-01-31').plus({months: 1}).plus({days: 5}).minus({days: 5}).minus({months: 1})
// => 2020-01-29 (order of operations in reverse, but result IS NOT the same as starting point)
Temporal.Date.from('2020-01-31').plus({months: 1}).plus({days: 5}).minus({months: 1}).minus({days: 5})
// => 2020-01-31 (order of operations not reversed, but result IS the same as starting point) @pipobscure - Was this how you expected it to work? Or was there a different kind of reversibility you had in mind? |
I think the most significant aspect of this is in the processing within individual operations, e.g. |
@gibson042 Does you mean that subtraction should also use largest-units-first? (Currently AFAIK the agreed-upon behavior is to reverse the order for subtraction, although I'm not sure how the polyfill and spec are currently implemented.) |
Essentially, yes. I don't think it makes any sense for |
I think this is different behavior from what @pipobscure has argued for in the past. Philipp could you take a look? |
I consider the examples tha @gibson042 gave edgecases. The relevant thing to me is: (pseudo code)
I achieved this by ensuring that difference never generated a duration where a part of the calculation created an invalid intermediate and reversing the order of operations for plus and minus. So to be clear it requires BOTH inverse order of operations AND difference being smart about how to split units. And that’s also why I consider the examples edge cases, because it entails manually specifying a bad unit split. P.S.: the reason for pseudo code is that I’m writing on my phone and therefore have limited reference material 😀 |
To clarify: @pipobscure would you expect that your pseudocode should work for all I tried to validate the pseudocode with real dates but ran into #993 which (assuming it's a legit bug) may prevent validating the pseudocode above in the current polyfill. Any insight you guys have about the expected behavior of #993 would be helpful. |
I'm going to close this issue because action items are all in #993. |
We previously decided that the order of operations in Temporal would be largest-units-first for addition and smallest-units-first for subtraction. The goal was for
a.plus(x).minus(x)
to always return the same value.My assumption that now with negative durations, it should work like this:
Is this correct?
The text was updated successfully, but these errors were encountered: