-
Notifications
You must be signed in to change notification settings - Fork 157
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
Eliminate duplication between Duration Records and Temporal.Duration instances #2943
Conversation
Also introduce operations to take the sign of a Date Duration Record and of a Normalized Duration Record, which replace some uses of DurationSign where there wasn't a Duration instance handy to pass to it. See: #2308
…te Duration Record See: #2308
Instead of picking a _sign_ of -1 or 1 and multiplying the components by it, create the Duration instance and then pass it through CreateNegatedTemporalDuration if the operation is ~since~. See: #2308
In the reference code, move AddISODate into calendar.mjs because it's only used once there (and replace the other calls of it with BalanceISODate.) This is a small step towards untangling the circular import in calendar.mjs. See: #2308
Similar to DifferenceTemporal___, instead of picking a _sign_ of -1 or 1 and multiplying the duration components by it, create the Duration instance and then pass it through CreateNegatedTemporalDuration if the operation is ~subtract~. This was already started in #2290, and brought into consistency everywhere in this commit. See: #2308
In order to avoid passing long lists of components, refactor Normalized Duration Records to have only two fields: a Date Duration Record and a Normalized Time Duration Record. This requires several changes throughout.
…normalize This is a pattern that we already mostly use, but now that everything is refactored to take Records instead of individual Duration components, it can be expressed much more concisely. See: #2308
…calc-unnormalize See: #2308
…c-unnormalize This allows inlining AddDateTime into AddDurationTo...PlainDateTime. It's the only place AddDateTime was used. See: #2308
…ulate-unnormalize See: #2308
In a few places, we did the operation of balancing the normalized time duration up to days, adding the days to the [[Days]] field of the date duration record, and discarding the time duration. Encapsulate this in its own AO. See: #2308
BalanceTimeDuration is now only used in UnnormalizeDuration. Inline it there. There is no longer any usage of Time Duration Records, so remove them. See: #2308
In a few places, we want to create a new Date Duration Record but with one or more fields adjusted, as if Date Duration Records had a with() method. This is easy to do with spreading and destructuring in JS, but is unwieldy in spec language. Add an AdjustDateDurationRecord abstract operation to do this more concisely. See: #2308
f5eab0a
to
df118ba
Compare
These are no longer necessary. We should either be using Normalized Duration Records (or their subcomponents, Date Duration Records and Normalized Time Duration Records) or Temporal.Duration instances. The records were still used in a few places: ToTemporalDurationRecord can be inlined into ToTemporalDuration since that is its only caller, and ParseTemporalDurationString can just return a Temporal.Duration instance directly. We keep ToTemporalDurationRecordRaw for the validStrings.js test.
df118ba
to
4cbf8c0
Compare
1. Let _dateDuration_ be CreateDurationRecord(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]] + _targetTime_.[[Days]], 0, 0, 0, 0, 0, 0). | ||
1. Let _dateDuration_ be ? AdjustDateDurationRecord(_normalizedDuration_.[[Date]], _targetTime_.[[Days]]). | ||
1. Let _targetDate_ be ? CalendarDateAdd(_calendar_, _isoRelativeToDate_, _dateDuration_, *"constrain"*). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this new ?
constitute a normative change? A surface reading suggests that an exception is now possible before CalendarDateAdd that was not possible before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this should be !
(and the same for your other comment below.) I'll fix this in a follow up PR. (Proof: targetTime.[[Days]] cannot exceed the original value of duration.[[Days]] because its absolute value can only be equal or smaller, coming out of AddTime.)
1. Let _dateDuration_ be CreateDurationRecord(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]] + _targetTime_.[[Days]], 0, 0, 0, 0, 0, 0). | ||
1. Let _dateDuration_ be ? AdjustDateDurationRecord(_normalizedDuration_.[[Date]], _targetTime_.[[Days]]). | ||
1. Let _targetDate_ be ? CalendarDateAdd(_calendar_, _isoRelativeToDate_, _dateDuration_, *"constrain"*). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here.
This was a mistake in #2943. _targetTime_.[[Days]] cannot exceed the original value of _duration_.[[Days]] here because its absolute value can only be equal or smaller coming out of AddTime.
This was a mistake in #2943. _targetTime_.[[Days]] cannot exceed the original value of _duration_.[[Days]] here because its absolute value can only be equal or smaller coming out of AddTime.
This was a mistake in #2943. _targetTime_.[[Days]] cannot exceed the original value of _duration_.[[Days]] here because its absolute value can only be equal or smaller coming out of AddTime.
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554
Here are a couple of stragglers from PR #2943.
Another couple of leftovers from PR #2943.
Here are a couple of stragglers from PR #2943.
Another couple of leftovers from PR #2943.
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554 UltraBlame original commit: de7fc134aa463dddcc4f75ff9ef2ba2b9b670a6f
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554 UltraBlame original commit: de7fc134aa463dddcc4f75ff9ef2ba2b9b670a6f
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554
A series of refactors that does three things:
Closes: #2308