Skip to content

size-suggestion: Remove Temporal.Calendar class and protocol #2854

@justingrant

Description

@justingrant

This issue was split from #2826. This issue is solely focused on removing the Calendar class and protocol. Please keep discussions on-topic.

Conclusion in the champions meeting of 2024-04-18. We've been asked to reduce the size and complexity of the proposal. The callable hooks in the time zone and calendar protocols are the part that implementations have been most uncomfortable with. They also seem to be where we get the biggest reduction in complexity for the least loss of use cases. The TimeZone and Calendar classes themselves make less sense to keep if the protocols are gone. So our conclusion is to remove them. This issue is focused on calendars only. A separate issue #2853 discusses time zones.

Motivations for removing custom calendars

  • A fundamental assumption in the design of the calendar protocol is that it'd be much more efficient to calculate each getter separately. Based on the experience of the team building ICU4X, this assumption has not held up. This has led to suggestions to optimize custom calendars to limit user code to a single method to calculate all calendar properties. (See size-suggestion: Should custom calendars eagerly calculate all fields at construction time? #2852.) This idea requires more validation, but could be a much simpler and more efficient solution to custom calendar use cases than the current Temporal design that involves many observable user code calls.
  • Requiring observable calls in a particular sequence makes it difficult for implementations to optimize, unless they maintain separate code paths for built-in vs. user-supplied calendars/time zones.
  • A future proposal could design a custom calendar implementation that requires much less code size, which is important because Temporal.Calendar has a very large surface area.
  • Custom calendars add a lot of complexity to the proposal, relative to cost in complexity and code size.
  • This functionality made more sense back when you could monkeypatch Calendar.from() to ‘register’ a custom ID. That ability was removed when the proposal went to stage 3 because the committee will not agree to global state.
  • Without a calendar protocol, there doesn’t seem to be much point in having a Temporal.Calendar object. All the functionality is still easily available through PlainDate methods and properties, (except for Calendar.p.fields() and Calendar.p.mergeFields() which are weird methods that only exist to make it possible to build custom calendars with extra fields.)

Use cases that disappear, and their replacements

Work around incomplete/outdated support in CLDR calendars

For example:

Replacement: Previously, you could implement a custom calendar by creating an object that implemented the protocol, and monkeypatching or wrapping some of Temporal so that it would deserialize dates with your custom calendar ID into a Temporal object with the correct protocol object. You would now have to monkeypatch or wrap more of Temporal. As part of moving this issue forward, we'll create a proof of concept for doing this, to make sure that it remains possible.

Scope of issue

  • Remove Temporal.Calendar
  • User-defined methods are not looked up nor called during calculations
  • Calendar-taking APIs no longer accept objects, only string IDs, and date/date-time strings from which an ID is determined
  • [[Calendar]] internal slot of PlainDate, PlainDateTime, PlainYearMonth, PlainMonthDay, ZonedDateTime only stores string ID
  • Remove getCalendar() methods from PlainDate, PlainDateTime, PlainYearMonth, PlainMonthDay, ZonedDateTime prototypes
  • calendar property of object returned by PlainDate, PlainDateTime, PlainYearMonth, PlainMonthDay, ZonedDateTime's getISOFields() methods can only be a string
  • Update TypeScript types to match the changes above.
  • Create proof of concept for how you would polyfill a custom calendar going forward

Metadata

Metadata

Assignees

Labels

size-suggestionSuggestions to shrink size of Temporal to address implementer concerns

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions