Replies: 2 comments 3 replies
-
That's cool that you are working on a custom calendar that's not yet in ICU! Here are some general tips and recommendations on implementing custom calendars: https://tc39.es/proposal-temporal/docs/calendar.html#custom-calendars I'll try to answer your questions more specifically:
That isn't really the expected way. The expected way would be that you extend If you are additionally writing a polyfill (for example, to add a calendar that newer browsers have support for and older browsers don't), then you'd also need to monkeypatch a lot of methods in order to be able to implement the string-to-calendar conversion, e.g. to be able to deserialize strings like
I assume you mean as the argument to the constructor? It's true that each calendar needs to have a builtin calendar ID passed in to the constructor. This ID determines how the methods behave when you chain up, e.g. with
The expectation is to implement everything from scratch unless you can implement it by chaining up to a method from Exporting these helpers seems like it could be a good use case for a separate calendar helper library (if it were to exist), not for a polyfill though — that might confuse people as to what is part of the proposal and what isn't. Those objects are likely to be removed in the future anyway. We have a vague plan to use ICU4X for calendar calculations instead of this custom code, although no timeline for this change.
Slots are a concept that kind of only has meaning in the specification. You can think of them as private properties. You don't need to take them into account when implementing a custom calendar. Good luck and I hope you'll share a link when you've got a first version! |
Beta Was this translation helpful? Give feedback.
-
thanks a lot @ptomato for the thorough explanation. Extremely helpful! I managed a first version here and seems to work as expected. I have some followup questions:
|
Beta Was this translation helpful? Give feedback.
-
I am trying to implement a custom calendar (nepali) based on the Temporal specs and js-temporal polyfill. So far, I could only do it by forking the library itself, is that the expected way? I am assuming I should implement the Calendar interface, and the problems I am having fall under two categories:
BuiltinCalendarId
type and there is no way to extend it.NonIsoImpl
andHelperBase
are not exported from the library so I have to duplicate a lot of the code to have a good starting point. can these be exported? or is the expectation for custom calendars to implement every thing from scratch?I am wary that I am potentially asking to expose implementation details that are not part of the specs, but I am wondering - in general - if you have any pointers or recommendations about how people should implement custom calendars?
Beta Was this translation helpful? Give feedback.
All reactions