-
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
Design of Temporal.Calendar and Temporal.TimeZone classes #300
Comments
This seems right to me; it enables non-subclasses to participate in the protocol, but the "happy path" is to subclass the builtin objects, and override methods. This assumes that |
@ljharb The proposed Temporal Calendar protocol is based on calling the methods, not the built-in ones. So a subclass of |
Yes, exactly right - but if they didnt shadow them they’d hit the builtin brand-checking ones. |
Carrying forward Temporal.TimeZone-specific requirements,
Some of those other use cases include denying or overriding lookup of host-provided time zones. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with calendar methods as a time zone, and makes the changes needed to allow that.
FIXME: Test fails passing custom time zone ID in to Intl FIXME: Need to remove ES.ToTemporalTimeZone and use Temporal.TimeZone.from throughout The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with calendar methods as a time zone, and makes the changes needed to allow that.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with getOffsetNanosecondsFor(), getPossibleAbsolutesFor(), and toString() as a time zone, and makes the changes needed to allow that: removing brand checks from time zone methods, and calling methods on Temporal.TimeZone.prototype if they are not present on the plain object.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with calendar methods as a time zone, and makes the changes needed to allow that.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with calendar methods as a time zone, and makes the changes needed to allow that.
The other half of the custom time zones and calendars protocol discussed in #300 was allowing calendars and time zones to be plain objects with the appropriate methods on them. This adds a test verifying that it's possible to use a plain object with calendar methods as a time zone, and makes the changes needed to allow that.
We had originally decided to go with a scheme where the value of the [[Identifier]] internal slot determines the behaviour of the calendar methods, and there are not individual parent classes for each built-in calendar. This implements that scheme. Merges most of the spec text of ISO8601Calendar into Calendar. Closes: #847 See: #300
We had originally decided to go with a scheme where the value of the [[Identifier]] internal slot determines the behaviour of the calendar methods, and there are not individual parent classes for each built-in calendar. This implements that scheme. Merges most of the spec text of ISO8601Calendar into Calendar. Closes: #847 See: #300
We had originally decided to go with a scheme where the value of the [[Identifier]] internal slot determines the behaviour of the calendar methods, and there are not individual parent classes for each built-in calendar. This implements that scheme. Merges most of the spec text of ISO8601Calendar into Calendar. Closes: #847 See: #300
We had originally decided to go with a scheme where the value of the [[Identifier]] internal slot determines the behaviour of the calendar methods, and there are not individual parent classes for each built-in calendar. This implements that scheme. Merges most of the spec text of ISO8601Calendar into Calendar. Closes: #847 See: #300
In other issues and documents, we've been talking about protocols for Temporal.Calendar and Temporal.TimeZone, so users could put in their own behavior for these. I didn't understand it at first, but the design is a really clean separation: ownership of time-related calculations simply moves from
Temporal.Time
andTemporal.DateTime
to the timezone objects, and similarly, date-related calculations move fromTemporal.Date
toTemporal.DateTime
.In this issue, I want to talk about how built-in instances work. How, when you pass "America/New_York" to
Temporal.DateTime.prototype.inTimeZone
, or{ calendar: "gregory" }
as part of the parameter toTemporal.DateTime.from
, this turns into an object which respects theTemporal.TimeZone
orTemporal.Calendar
protocol.The rest of post describes details for
Temporal.Calendar
, just because there's more written up about the protocol and less about the class. I suspect that the same sorts of logic will make sense forTemporal.TimeZone
as well. Some people have alluded to alternatives, but I can't figure out what they would be concretely, so I'm just focusing on my ideas to start things off. I encourage you to post any other ideas to this thread for discussion.The Temporal Calendar protocol is described here. One class whose instances conform to this protocol is
Temporal.Calendar
. This class is used for both the"iso"
calendar and calendars defined in ECMA-402.Instances have a [[CalendarName]] internal slot, which is a string like
"iso"
or"chinese"
. All methods (such asTemporal.Calendar.prototype[Temporal.Calendar.plus]
) start by checking for the presence of an [[InitializedTemporalCalendar]] internal slot, throwing a TypeError otherwise, and if it's fine, using the [[CalendarName]] internal slot by doing the appropriate calculation.The Temporal Calendar protocol operates by simply calling methods; there is no reference to the [[CalendarName]] internal slot by users of the Temporal Calendar protocol (such as
Temporal.Date.prototype.plus
). The internal slot is only referenced by the methods withinTemporal.Calendar.prototype
.The layering of ECMA-402 is explained by the definitions of the methods and constructor for Calendar to be patched/replaced by ECMA-402; there's separate class for them. This is analogous to the
toLocaleString()
methods.The
Temporal.Calendar
constructor (which requires explicitnew
) takes a string as an argument and looks up if there's a built-in calendar with this name (using the same logic as Intl with respect to normalization). If there is, it constructs a freshTemporal.Calendar
instance with the [[CalendarName]] internal slot set appropriately. If no calendar is found, then a RangeError is thrown. TheTemporal.Calendar.from
method will callnew Temporal.Calendar
if passed a string, return the object if passed an object, and throw a TypeError otherwise.Specification-wise, when creating an object that has a calendar (such as a
Temporal.Date
instance), a new instance is created immediately, as if byTemporal.Calendar.from
. In the implementation, though, if a string is used, then the calendar could unobservably be stored in theTemporal.Date
as its corresponding string, with the allocation delayed until someone actually accesses the calendar with theget Temporal.Date.prototype.calendar
accessor (and then, in that case, cached in place).The text was updated successfully, but these errors were encountered: