Cookbook example showing custom calendar proof of concept (without custom calendar object)#2906
Cookbook example showing custom calendar proof of concept (without custom calendar object)#2906
Conversation
|
thanks @ptomato - this is very helpful (and re-assuring). |
When I removed the cookbook-loader.mjs, I accidentally broke the test-cookbook-one script in package.json. It made the tests always pass because the actual test was no longer loaded due to the presence of the --eval command line argument. Instead, use --require to define a global assert property.
8f3c01a to
e9aa23e
Compare
|
I found some time to clean this up and make a cookbook page for it. It's ready for review now. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2906 +/- ##
=======================================
Coverage 96.85% 96.85%
=======================================
Files 21 21
Lines 9969 9969
Branches 1823 1823
=======================================
Hits 9655 9655
Misses 268 268
Partials 46 46 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a page showing how to do a custom calendar by creating a class that works like PlainDate, but implements a calendar that isn't built in to JavaScript.
e9aa23e to
78179d8
Compare
|
@sffc Did you still want to review this? I'd like to get it done soon. |
sffc
left a comment
There was a problem hiding this comment.
Praise: Very clear and well-commented!
I didn't verify the calendar arithmetic for correctness.
|
Thanks for taking a look. I just implemented the calendar arithmetic that was in the other library that I credited, so I haven't done any research on correctness. I think that's OK for a cookbook example. Hopefully we will get feedback if it isn't accurate 😄 |
This is an example of how to approach implementing a custom calendar, after Temporal.Calendar objects are removed.
It's an implementation of a Nepali calendar (described by @kabaros in #2854 (comment)) based on the implementation linked in that comment, as well as the implementation that was based on.
I used inheritance in this example because in this case that's slightly less code to write, but inheritance also makes some operations legal that maybe shouldn't be. (Like,Temporal.PlainDateTime.from(nepaliPlainDate)) So it might be better to switch to composition.I'd also like to write a similar example about Hijri dates with manual adjustment (described in #2854 (comment)) but it was easier to do the proof of concept with Nepali calendar first, since there was already an implementation to copy from. I'll be in contact with @khawarizmus about this.Draft; needs some cleanup, and a cookbook page.