Skip to content

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

Merged
sffc merged 1 commit intounicode-org:mainfrom
afrdbaig7:fix/hour-cycle-default-594-clean
May 1, 2026
Merged

Add regression tests for locale default hour cycle (Fixes #594)#7652
sffc merged 1 commit intounicode-org:mainfrom
afrdbaig7:fix/hour-cycle-default-594-clean

Conversation

@afrdbaig7
Copy link
Copy Markdown
Contributor

@afrdbaig7 afrdbaig7 commented Feb 13, 2026

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.

Changelog

Add regression tests for components::Bag::hour_cycle resolution across locales.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

sffc commented Feb 20, 2026

Please fix the merge conflict

@sffc
Copy link
Copy Markdown
Member

sffc commented Feb 27, 2026

Please fix clippy. Thanks

@afrdbaig7 afrdbaig7 requested a review from sffc February 28, 2026 14:55
.unwrap();
let formatted = formatter.format(&datetime);
let resolved_pattern = formatted.pattern();
let bag = components::Bag::from(&resolved_pattern);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Observation: the main thing you are testing in this PR is the behavior of components::Bag::hour_cycle.

There is one small test that does this, test_length_time

We also have test_hour_cycle_selection which tests the hour cycle resolution through DateTimeFormatterPreferences but not all the way through to components::Bag

So I lean toward believing that this test is a value-add, but we have this behavior mostly already tested elsewhere.

I would be more confident if you moved the test into resolved_components.rs and described it as being a more thorough test of components::Bag::hour_cycle.

@robertbastian robertbastian requested a review from sffc April 27, 2026 12:03
Copy link
Copy Markdown
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.

(@afrdbaig7 please address my comment from above)

@afrdbaig7
Copy link
Copy Markdown
Contributor Author

(@afrdbaig7 please address my comment from above)
Thanks for the reminder will push an update shortly.

@afrdbaig7 afrdbaig7 requested a review from sffc April 29, 2026 18:38
Copy link
Copy Markdown
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.

Thanks, please fix the fmt error and then we can merge

@afrdbaig7
Copy link
Copy Markdown
Contributor Author

afrdbaig7 commented Apr 30, 2026

Thanks, please fix the fmt error and then we can merge

Ok i will fix it and push the update shortly

@afrdbaig7 afrdbaig7 force-pushed the fix/hour-cycle-default-594-clean branch 3 times, most recently from f70e40e to 463dbc5 Compare May 1, 2026 04:49
@afrdbaig7 afrdbaig7 force-pushed the fix/hour-cycle-default-594-clean branch from 463dbc5 to 4f7319f Compare May 1, 2026 04:59
@afrdbaig7 afrdbaig7 requested a review from sffc May 1, 2026 05:15
@afrdbaig7
Copy link
Copy Markdown
Contributor Author

@sffc Thanks for your help I’ve addressed your comment.
I’d like to continue contributing, so I’ll start exploring other open issues as well.
Also, is there a preferred community channel (Discord/Slack) where contributors usually coordinate?

@sffc sffc merged commit 7b557f5 into unicode-org:main May 1, 2026
34 checks passed
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

3 participants