Skip to content

Comments

Add regression tests for locale default hour cycle (Fixes #594)#7652

Open
afrdbaig7 wants to merge 2 commits intounicode-org:mainfrom
afrdbaig7:fix/hour-cycle-default-594-clean
Open

Add regression tests for locale default hour cycle (Fixes #594)#7652
afrdbaig7 wants to merge 2 commits intounicode-org:mainfrom
afrdbaig7:fix/hour-cycle-default-594-clean

Conversation

@afrdbaig7
Copy link
Contributor

Fixes #594

This PR adds regression tests to make sure datetime formatting falls back
to the correct default hour cycle based on CLDR region data when no
explicit -u-hc- preference is provided.
I added both runtime and datagen tests so that the behavior is covered
at formatting time as well as at the data level.

Runtime tests (simple_test.rs):

  • Check default behavior:
    • en → h12
    • fr, ja, en-GB → h23
  • Verify that explicit -u-hc- overrides still take priority
  • Add a midnight edge case to ensure formatting is correct

Datagen test (semantic_skeletons/tests.rs):

  • Validate that preferred_hour_cycle() returns the expected
    CoarseHourCycle:
    • en → H11H12
    • fr, ja, en-ZA → H2
      Note: The runtime tests require feature = "experimental" for
      components::Bag access.
      These tests should help prevent regressions and make the expected
      locale-based hour cycle behavior more clearly covered.

Copy link
Contributor

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 adds comprehensive regression tests for issue #594, ensuring that datetime formatting correctly falls back to locale-specific default hour cycles based on CLDR region data when no explicit -u-hc- preference is provided.

Changes:

  • Added datagen test to validate that preferred_hour_cycle() correctly infers hour cycles from CLDR data
  • Added runtime test to verify that datetime formatting uses the correct default hour cycle for various locales
  • Included tests for explicit -u-hc- overrides and midnight edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
provider/source/src/datetime/semantic_skeletons/tests.rs Adds test_preferred_hour_cycle_by_locale() to validate datagen pipeline correctly infers locale-specific hour cycles from CLDR patterns
components/datetime/tests/simple_test.rs Adds test_locale_default_hour_cycle() to verify runtime formatting behavior with default and explicit hour cycle preferences

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for (locale_str, expected_hour_cycle) in cases {
let locale: Locale = locale_str.parse().unwrap();
let prefs = DateTimeFormatterPreferences::from(&locale);
let formatter = FixedCalendarDateTimeFormatter::<icu_calendar::Gregorian, _>::try_new(
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Consider importing Gregorian from icu_calendar at the top of the file and using the shorter Gregorian instead of the fully qualified icu_calendar::Gregorian. This would be consistent with other test files like resolved_components.rs that import and use Gregorian directly.

Copilot uses AI. Check for mistakes.
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.

I think we have tests for this already, but adding additional tests specifically for the components::Bag behavior as integration tests is harmless and directly fixes the issue.

@afrdbaig7 afrdbaig7 requested a review from sffc February 18, 2026 00:55
@afrdbaig7
Copy link
Contributor Author

I think we have tests for this already, but adding additional tests specifically for the components::Bag behavior as integration tests is harmless and directly fixes the issue.

Thanks for the review
Yes, the main addition here is the components::Bag integration test in simple_test.rs. It structurally checks the resolved hour_cycle for different locales (for example, en → H12 and fr/ja/en-GB → H23). It also covers explicit -u-hc- overrides to make sure they still take precedence, along with a midnight edge case to ensure formatting behaves correctly.
Additionally, I added a datagen-level test in semantic_skeletons/tests.rs that verifies preferred_hour_cycle() directly against the CLDR source data. This acts as an extra safety check so that both the data layer and the runtime behavior stay aligned.

@sffc
Copy link
Member

sffc commented Feb 20, 2026

Please fix the merge conflict

…#594)

Add tests to ensure datetime formatting correctly falls back to the
locale's default hour cycle based on CLDR region data when no explicit
-u-hc- preference is provided.

Runtime tests (simple_test.rs):
- Verify default behavior:
  - en → h12
  - fr, ja, en-GB → h23
- Ensure explicit -u-hc- overrides take priority
- Cover midnight edge case formatting

Datagen test (semantic_skeletons/tests.rs):
- Verify preferred_hour_cycle() returns expected CoarseHourCycle:
  - en → H11H12
  - fr, ja, en-ZA → H23

These tests help prevent regressions and make the locale-driven hour
cycle behavior explicit and well-covered.
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.

Choose a default hour cycle for a locale when no preferences are provided

2 participants