Skip to content

Cookbook example showing custom calendar proof of concept (without custom calendar object)#2906

Merged
ptomato merged 2 commits intomainfrom
cookbook-custom-calendar
Jul 10, 2025
Merged

Cookbook example showing custom calendar proof of concept (without custom calendar object)#2906
ptomato merged 2 commits intomainfrom
cookbook-custom-calendar

Conversation

@ptomato
Copy link
Collaborator

@ptomato ptomato commented Jun 26, 2024

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.

@ptomato ptomato marked this pull request as draft June 26, 2024 21:27
@kabaros
Copy link

kabaros commented Jun 27, 2024

thanks @ptomato - this is very helpful (and re-assuring).

@justingrant justingrant added documentation Additions to documentation no-spec-text PR can be ignored by implementors labels Oct 9, 2024
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.
@ptomato ptomato force-pushed the cookbook-custom-calendar branch from 8f3c01a to e9aa23e Compare May 14, 2025 19:11
@ptomato ptomato assigned ptomato and unassigned ptomato May 14, 2025
@ptomato ptomato marked this pull request as ready for review May 14, 2025 19:12
@ptomato
Copy link
Collaborator Author

ptomato commented May 14, 2025

I found some time to clean this up and make a cookbook page for it. It's ready for review now.

@codecov
Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.85%. Comparing base (87c74ec) to head (78179d8).
Report is 13 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather nice.

@sffc sffc self-requested a review May 16, 2025 09:18
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.
@ptomato ptomato force-pushed the cookbook-custom-calendar branch from e9aa23e to 78179d8 Compare May 16, 2025 16:07
@ptomato ptomato changed the title WIP: Cookbook example showing custom calendar proof of concept (without custom calendar object) Cookbook example showing custom calendar proof of concept (without custom calendar object) Jul 9, 2025
@ptomato
Copy link
Collaborator Author

ptomato commented Jul 9, 2025

@sffc Did you still want to review this? I'd like to get it done soon.

Copy link
Collaborator

@sffc sffc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: Very clear and well-commented!

I didn't verify the calendar arithmetic for correctness.

@ptomato
Copy link
Collaborator Author

ptomato commented Jul 10, 2025

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 😄

@ptomato ptomato merged commit 2a9fec8 into main Jul 10, 2025
10 checks passed
@ptomato ptomato deleted the cookbook-custom-calendar branch July 10, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Additions to documentation no-spec-text PR can be ignored by implementors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants