Skip to content

fix(intl): #5840 — Intl.DateTimeFormat dayPeriod-only formatting (6 test262 cases) - #5862

Merged
proggeramlug merged 2 commits into
mainfrom
worktree-issue-5840-dtf-intl402
Jul 2, 2026
Merged

fix(intl): #5840 — Intl.DateTimeFormat dayPeriod-only formatting (6 test262 cases)#5862
proggeramlug merged 2 commits into
mainfrom
worktree-issue-5840-dtf-intl402

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the dayPeriod-only subcluster of the test262 intl402/DateTimeFormat — 51 (self-contained worklist) #5840 intl402/DateTimeFormat worklist. new Intl.DateTimeFormat('en', {dayPeriod: 'long'}) (no other date/time component options) silently fell back to the default M/D/YYYY date string in both format and formatToPartsdtf_primary_mask never counted dayPeriod toward its time-dimension bit, and neither format_components nor build_parts_from_components had any dayPeriod rendering path (dayPeriod was previously only ever emitted as a byproduct of the AM/PM 12-hour clock).
  • Adds day_period_string(hour, style): en CLDR day-period boundaries at hour granularity (0-11 morning, 12 noon, 13-17 afternoon, 18-20 evening, 21-23 night; narrow abbreviates only "noon" → "n"), verified empirically against node.
  • Threads a day_period_opt parameter through format_components/build_parts_from_components: dayPeriod-only renders just the period text (one part in formatToParts); combined with a numeric hour it renders "<hour> <period>" ([hour, literal " ", dayPeriod] in formatToParts), replacing the default AM/PM suffix. Behavior is unchanged when day_period_opt is None.

Fixes: prototype/format/dayPeriod-{long,narrow,short}-en.js, prototype/formatToParts/dayPeriod-{long,narrow,short}-en.js.

Test plan

  • scripts/test262_subset.py --root vendor/test262 --dir intl402/DateTimeFormat (run under TZ=UTC — Perry's DTF hardcodes a UTC default timeZone while Date's local-component constructor honors the real host offset, so a non-UTC dev box shows an unrelated pre-existing hour-shift on new Date(y,m,d,h,...)-based cases; CI runs UTC): 6 target cases fixed, zero regressions (45 remaining failures = exactly the other 45 of the original 51-case worklist).
  • cargo fmt --all -- --check
  • bash scripts/check_file_size.sh (date_collator.rs: 1951/2000 lines)
  • scripts/run_gap_tests.sh — pre-existing gap failures unrelated to this change confirmed via git stash bisection (e.g. test_gap_console_bare_global reproduces identically on unmodified main).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Date and time formatting now supports dayPeriod labels (morning/afternoon/evening and equivalents) more broadly, including formatToParts output.
    • format/formatToParts handle dayPeriod-only cases and combined dayPeriod + numeric hour cases more consistently.
  • Bug Fixes

    • Fixed incorrect dayPeriod option handling that could cause misclassification and incorrect rendering.
    • Improved locale-aware suffix/label behavior for both 24-hour and 12-hour output.
  • Documentation

    • Updated the changelog and current version to v0.5.1211.

…est262 cases)

new Intl.DateTimeFormat('en', {dayPeriod: 'long'}) (no other date/time
component options) silently fell back to the default M/D/YYYY date string in
both format and formatToParts: dtf_primary_mask never counted dayPeriod
toward its time-dimension bit, and format_components/build_parts_from_components
had no dayPeriod rendering path at all.

- day_period_string(hour, style): en CLDR day-period boundaries at hour
  granularity, verified empirically against node.
- dtf_primary_mask sets BIT_TIME for dayPeriod so a dayPeriod-only DTF isn't
  misclassified as having no primary fields.
- format_components/build_parts_from_components thread a day_period_opt
  through: dayPeriod-only renders just the period text; combined with a
  numeric hour it renders "<hour> <period>", replacing the AM/PM suffix.
  Unchanged when day_period_opt is None.

Fixes the 6 dayPeriod-*-en.js cases from the #5840 worklist with zero
regressions (verified via scripts/test262_subset.py under TZ=UTC).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ebde5c53-b3b6-412f-b6c7-fd35da358fb2

📥 Commits

Reviewing files that changed from the base of the PR and between 897d088 and 2aaa80f.

📒 Files selected for processing (1)
  • crates/perry-runtime/src/intl/date_collator.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/perry-runtime/src/intl/date_collator.rs

📝 Walkthrough

Walkthrough

This PR adds dayPeriod support to Intl.DateTimeFormat formatting in date_collator.rs, covering format/formatToParts output, a new day_period_string helper, and updated dtf_primary_mask classification. Version metadata is bumped to 0.5.1211 with a corresponding changelog entry.

Changes

dayPeriod formatting support

Layer / File(s) Summary
day_period_string helper and mask classification
crates/perry-runtime/src/intl/date_collator.rs
Introduces day_period_string(hour, style) producing English day-period labels and updates dtf_primary_mask so dayPeriod participates in primary time-field overlap checks.
formatToParts dayPeriod part emission
crates/perry-runtime/src/intl/date_collator.rs
Extracts KEY_DAY_PERIOD into day_period_opt, threads it through build_parts_from_components, and emits dayPeriod parts in both 24-hour and 12-hour component formatting paths.
format() string composition with dayPeriod
crates/perry-runtime/src/intl/date_collator.rs
Updates format_components to accept day_period_opt, adjusts has_time, appends day-period labels in string output, and threads the option through DTF and Temporal formatting paths.
Version bump and changelog entry
CLAUDE.md, Cargo.toml, CHANGELOG.md
Bumps version to 0.5.1211 and documents the dayPeriod fix in the changelog.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant DateCollator
  participant DayPeriodString

  Caller->>DateCollator: formatToParts(options with KEY_DAY_PERIOD)
  DateCollator->>DateCollator: extract day_period_opt
  DateCollator->>DateCollator: build_parts_from_components(day_period_opt)
  DateCollator->>DayPeriodString: day_period_string(hour, style)
  DayPeriodString-->>DateCollator: label
  DateCollator-->>Caller: parts including dayPeriod
Loading

Possibly related PRs

  • PerryTS/perry#5765: Both PRs modify format_components plumbing in date_collator.rs, extended here with dayPeriod handling.
  • PerryTS/perry#5782: Both PRs change how Intl.DateTimeFormat options thread through format/formatToParts, with this PR adding dayPeriod.
  • PerryTS/perry#5807: Both PRs extend format_components/component composition logic in date_collator.rs.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: Intl.DateTimeFormat dayPeriod-only formatting fixes tied to #5840.
Description check ✅ Passed The description covers the fix, key implementation details, related issue, and test plan; only non-critical template sections are omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-issue-5840-dtf-intl402

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/perry-runtime/src/intl/date_collator.rs (1)

1509-1518: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Thread dayPeriod through Temporal locale formatting. has_component still ignores dayPeriod, and the final format_components call passes None, so { dayPeriod: 'long' } is treated as if no option was set.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry-runtime/src/intl/date_collator.rs` around lines 1509 - 1518, The
Temporal locale formatting path is dropping dayPeriod, so `{ dayPeriod: 'long'
}` is ignored. Update the relevant `has_component` logic and the
`format_components` call in `date_collator.rs` to thread the `dayPeriod` option
through instead of hardcoding `None`, using the existing `dayPeriod`-related
symbols alongside `weekday_opt` and `era_opt`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/perry-runtime/src/intl/date_collator.rs`:
- Around line 840-858: Update day_period_string in date_collator.rs to use the
correct English CLDR boundaries: map 0 to “midnight”, 1..=5 to “at night”,
6..=11 to “in the morning”, keep 12 as “noon”, and preserve the
afternoon/evening ranges. Also update the narrow-style handling so midnight
becomes “mi” and noon remains “n”, with the style override applied based on the
computed period string.

---

Outside diff comments:
In `@crates/perry-runtime/src/intl/date_collator.rs`:
- Around line 1509-1518: The Temporal locale formatting path is dropping
dayPeriod, so `{ dayPeriod: 'long' }` is ignored. Update the relevant
`has_component` logic and the `format_components` call in `date_collator.rs` to
thread the `dayPeriod` option through instead of hardcoding `None`, using the
existing `dayPeriod`-related symbols alongside `weekday_opt` and `era_opt`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 008e5e37-bbe0-490b-950e-34f7c72922f4

📥 Commits

Reviewing files that changed from the base of the PR and between b566ea7 and 897d088.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • CHANGELOG.md
  • CLAUDE.md
  • Cargo.toml
  • crates/perry-runtime/src/intl/date_collator.rs

Comment thread crates/perry-runtime/src/intl/date_collator.rs
…eedback)

temporal_locale_string read every other DTF component option but never
dayPeriod, so has_component ignored it and the final format_components
call hardcoded None — Temporal.PlainDateTime(...).toLocaleString('en',
{dayPeriod: 'long'}) silently ignored the option. Thread it through like
weekday/era. Re-verified via test262_subset.py: same 45 remaining
failures, zero regressions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@proggeramlug
proggeramlug merged commit 02dfb46 into main Jul 2, 2026
15 checks passed
@proggeramlug
proggeramlug deleted the worktree-issue-5840-dtf-intl402 branch July 2, 2026 05:02
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.

1 participant