You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor calendars to eliminate multiple parent classes
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
For specialized applications where you need to do calculations in a calendar system that is not supported by Intl, you can implement a custom calendar.
42
42
There are two ways to do this.
43
43
44
-
The recommended way is to create a class inheriting from `Temporal.Calendar`, call `super()` in the constructor with a calendar identifier string, and implement all the members except `id`, `toString()`, and `fields()`, which are optional.
45
-
If you don't implement the optional members, then the base class's default implementations will be used.
44
+
The recommended way is to create a class inheriting from `Temporal.Calendar`.
45
+
You must use one of the built-in calendars as the "base calendar".
46
+
In the class's constructor, call `super()` with the identifier of the base calendar.
47
+
The class must override `toString()` to return its own identifier.
48
+
Overriding all the other members is optional.
49
+
If you don't override the optional members, then they will behave as in the base calendar.
46
50
47
51
The other, more difficult, way to create a custom calendar is to create a plain object implementing the `Temporal.Calendar` protocol, without subclassing.
48
-
The object must implement all of the `Temporal.Calendar` methods except for `fields()`.
52
+
The object must implement all of the `Temporal.Calendar` methods except for `id` and `fields()`.
49
53
Any object with the required methods will return the correct output from any Temporal property or method.
50
54
However, most other code will assume that custom calendars act like built-in `Temporal.Calendar` objects.
51
55
To interoperate with libraries or other code that you didn't write, then you should implement the `id` property and the `fields()` method as well.
0 commit comments