Repository navigation
fix(shared): derive the day period from the hour, not a localized string - #2958
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: unovue/reka-ui/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe formatter now derives AM/PM from a fixed 24-hour value. Tests cover localized formats, formatter options, time zones, locale changes, DateField, and TimeField hour editing. ChangesDay-period handling
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
`useDateFormatter`'s `dayPeriod` matched the formatted day period against `PM`/`pm`/`p.m.` and fell back to `AM` for anything else. Locales that render it in another form always resolved to `AM`, so an afternoon value displayed as AM and retyping the hour silently moved the time back twelve hours. Read the hour on a pinned 24-hour, Latin-digit clock and compare it against 12 instead, which is how `handleHourSegmentKeydown` and `handleSegmentFocusOut` already derive the token. `hour12` is cleared explicitly because it takes precedence over `hourCycle` in `Intl`. This covers DateField, DateRangeField, TimeField and TimeRangeField, which all resolve the day period through the shared `syncTimeSegmentValues`. Closes #2956 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3e23a3e to
ad2495f
Compare
commit: |
🔗 Linked issue
Resolves #2956
❓ Type of change
📚 Description
useDateFormatter().dayPeriod()matched the formatted day period againstPM/pm/p.m.and fell back toAMfor anything else. Locales that render it differently (p. m.ines-ES,午後inja-JP,下午inzh-CN,오후inko-KR, …) therefore always resolved toAM. Withhour-cycle="12", an afternoon value displayed as AM, and retyping the hour silently moved the time back twelve hours (15:30 → 03:30).Fix: read the hour on a 24-hour clock and compare it against 12, the same way
handleHourSegmentKeydownandhandleSegmentFocusOutalready derive the token. This was the only place insrcthat string-matched the day period.hourCycle: 'h23'andnumberingSystem: 'latn'are pinned so the hour always parses as a Latin-digit 0–23 value (coversar-EG,fa-IR, …).hour12is cleared explicitly. It takes precedence overhourCycleinIntl, so a caller passinghour12: truetouseDateFormatterwould otherwise get every afternoon back as AM.Formatter.dayPeriodsignature is unchanged.Because the day period flows through the shared
syncTimeSegmentValues, this fixes DateField, DateRangeField, TimeField and TimeRangeField together.Tests
useDateFormatter.test.ts: 15 locales × 5 hours, everyhourCycle/hour12option, a non-Gregorian calendar,opts.timeZone, andsetLocale. Everything is pinned to UTC, so results don't depend on the runner's zone.DateFieldandTimeField: render and hour-retype cases across the affected locales.v2and all pass with the fix. The full suite passes (2252 tests), along with type-check (test files included), build and lint.Relation to #2953
#2953 has since merged. It added a
timeZoneparameter to the same function for foreign-zoneZonedDateTimevalues. This branch is rebased on it and keeps that parameter, with a unit test for it, so both fixes stay in place.Not in scope
The segment still shows the
AM/PMtoken in every locale rather than a localized string such as午後. That comes from the publicDayPeriodtype and the placeholder design, not from this bug, and changing it would alter output for every non-English locale.📝 Checklist
🤖 Generated with Claude Code
Summary by CodeRabbit