Skip to content
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

Can the overlap between Duration instances and Duration Records be eliminated? #2308

Open
gibson042 opened this issue Jun 16, 2022 · 2 comments
Assignees
Labels
editorial spec-text Specification text involved
Milestone

Comments

@gibson042
Copy link
Collaborator

Copied from #2281 (review)

Both Duration instances and Duration Records have the same set of immutable fields (with an extra branding field for the former), and the spec provides no internal guidance about when to use one vs. the other, resulting in muddled treatment1.

I think Duration Record should be eliminated altogether, or else Duration instances should be refactored to have a field containing a Duration Record rather than duplicating its fields.

Footnotes

  1. Temporal.Duration.compare and Temporal.Calendar.prototype.dateAdd include surprising examples, and the apparent pattern of DifferenceTemporal… operations returning Temporal.Duration instances vs. other Difference… operations returning Records or in some cases mathematical values is an extremely subtle one and appears to be wholly undocumented.

@ljharb
Copy link
Member

ljharb commented Jun 16, 2022

I love either of those outcomes.

@ptomato
Copy link
Collaborator

ptomato commented Jun 20, 2022

I believe we had this distinction so that nobody would be tempted to observably call methods on Duration instances in internal algorithms, similar to what we did with the other types. I do like that separation because it is clear that if you have a Duration Record, it should never be user-visible.

Also because for a long time it wasn't clear, at least to me, under what circumstances OrdinaryCreateFromConstructor and therefore CreateTemporalDuration could throw.

The use of Duration instances internally in the newly-added DifferenceTemporal... operations is something I personally don't like, but the amount of deduplication enabled by those operations outweighed the disadvantage for me.

@ptomato ptomato added editorial spec-text Specification text involved labels Dec 8, 2022
@ptomato ptomato added this to the Stage 4 milestone Dec 8, 2022
@ptomato ptomato self-assigned this Sep 13, 2024
@ptomato ptomato modified the milestones: Stage 4, Stage "3.5" Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial spec-text Specification text involved
Projects
None yet
Development

No branches or pull requests

3 participants