Skip to content

Conversation

Manishearth
Copy link
Member

Attempting to address #4917, #5068, https://issues.chromium.org/issues/439624688.

Related: #5778

tc39/proposal-temporal#2869 has told us that we are allowed to break calendar-internal invariants outside of the useful range of the calendar.

We currently hit debug assertions for some of these dates. This patches it up by

This is a partial PR, I haven't fixed all of the assertions. We'll likely have to make the function in calendrical_calculations pub+hidden (or make a copy in icu_calendar) and use it.

I would like feedback on the approach.

@Manishearth Manishearth requested a review from sffc August 18, 2025 23:45
Copy link
Member

@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.

Ok. Relaxing the calendar-specific guarantees outside of a very large range seems reasonable and sufficiently orthogonal to the other questions about proleptic approximations.

}

// Assertion failure:
// > assertion failed: Date::try_new_ummalqura_date(y, m, d, IslamicUmmAlQura::new_always_calculating()).is_ok()
Copy link
Member

Choose a reason for hiding this comment

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

UAQ is not an astronomical calendar and it doesn't have this constructor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this is just the old test that anba wrote.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should still test that it doesn't panic.

Copy link
Member

Choose a reason for hiding this comment

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

then you might as well test that Gregorian doesn't panic. there is no astronomical code

Copy link
Member Author

@Manishearth Manishearth Aug 29, 2025

Choose a reason for hiding this comment

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

Yeah but it feels like overkill to test all the calendars. These are the iffy ones, some iffier than others. It's a test, it's fine if it tests extra things.

A client (anba) found it useful to test this, so I'm keeping it in.

Copy link
Member Author

Choose a reason for hiding this comment

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

The purpose of this test is not to test that the code in this PR is doing something. The purpose of this test is to test that large Temporal-allowed dates work without panicking in the calendars that have calendrical debug assertions. We should ideally test more dates.

In the future if we moved the chinese calendar over to the pinqi approximation I would still wish to continue testing it here.

Copy link
Member

Choose a reason for hiding this comment

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

by that logic we might change the implementation of every calendar, or add debug assertions to any calendar. then just add these tests to any_calendar.rs which has tests for all calendars.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean yeah but it's only a couple calendars that are insufficiently defined outside the modern range. I think there's a pretty clear destination here.

But I might just make this an AnyCalendar test. I hadn't done that mostly because I was trying to reuse anba's test, and also the current AnyCalendar test is kind of annoyingly merged. Might try and clean it up a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added more calendars.

any_calendar.rs has a massive omnibus test that I do not think we should expand. A good refactor to do here would be to design a "for all calendars" test utility.

Until then, I added some more calendars. I do not think we need to exhaustively list them all. I do think adding extra tests protects us from future issues.

Copy link
Member

Choose a reason for hiding this comment

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

We should definitely test the calendars that are known-astronomical. For others, we can accept these unit tests but not necessarily require that they all be covered consistently.

@sffc sffc requested a review from Copilot August 26, 2025 21:31
@sffc
Copy link
Member

sffc commented Aug 26, 2025

/gemini review

Copilot

This comment was marked as outdated.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to handle extreme dates in astronomical calendars by defining a 'well-behaved' range for RataDie. The new function RataDie::in_well_behaved_astronomical_range() is used to suppress debug assertions that would otherwise panic for dates far in the past or future. This change is applied to the Chinese-based and Islamic calendars. Additionally, a new test suite is added to ensure these extreme dates no longer cause panics. The approach is solid and effectively addresses the reported issues. I have one suggestion to improve the implementation of the new function by using constants for magic numbers, which will enhance readability and maintainability.

@Manishearth Manishearth force-pushed the valid-astronomical-range branch from 15d3036 to 0de8442 Compare August 28, 2025 22:15
@Manishearth Manishearth marked this pull request as ready for review August 28, 2025 22:16
@Manishearth Manishearth requested a review from a team as a code owner August 28, 2025 22:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses panic issues in astronomical calendars when processing dates outside well-behaved ranges by adding range checks to debug assertions. The changes introduce a WELL_BEHAVED_ASTRONOMICAL_RANGE constant and modify debug assertions to skip invariant checks for dates outside this range, preventing panics in extreme date scenarios while maintaining calendar correctness within expected ranges.

Key changes:

  • Added WELL_BEHAVED_ASTRONOMICAL_RANGE constant to define the astronomical validity range
  • Modified debug assertions across multiple calendar implementations to skip checks outside the well-behaved range
  • Added test cases to verify extreme date handling

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
utils/calendrical_calculations/src/chinese_based.rs Added range constant and updated debug assertions for Chinese-based calendar calculations
utils/calendrical_calculations/src/islamic.rs Re-exported the range constant and updated Saudi Islamic calendar assertions
components/calendar/src/provider/chinese_based.rs Modified PackedChineseBasedYearInfo to handle out-of-range dates with clamping
components/calendar/src/cal/hijri.rs Updated Hijri calendar debug assertions to use the astronomical range check
components/calendar/src/cal/chinese_based.rs Added range checks for Chinese-based calendar date conversions
components/calendar/src/tests/extrema.rs Added new test file to verify extreme date handling
components/calendar/src/tests/mod.rs Added the new extrema test module

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

// Assertion failure:
// > assertion failed: Date::try_new_ummalqura_date(y, m, d, IslamicUmmAlQura::new_always_calculating()).is_ok()
Copy link
Member

Choose a reason for hiding this comment

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

by that logic we might change the implementation of every calendar, or add debug assertions to any calendar. then just add these tests to any_calendar.rs which has tests for all calendars.

sffc
sffc previously approved these changes Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants