Skip to content

fix(date-field): show PM times correctly in 12-hour display - #586

Merged
interacsean merged 1 commit into
mainfrom
fix/2039-date-field-12-hour-pm
Oct 9, 2026
Merged

interacsean merged 1 commit into
mainfrom
fix/2039-date-field-12-hour-pm

Conversation

@interacsean

@interacsean interacsean commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes tailor-inc/platform-planning#2039

Problem

With granularity at hour/minute/second and a 12-hour cycle (hourCycle={12} or a 12-hour locale like en-US), DateField / DatePicker / DateRangePicker showed afternoon values as e.g. "18:00 AM", and editing any segment emitted the value 12 hours early (06:xx).

fieldsFromValue() copied the 0–23 hour straight into the segments and never set dayPeriod, while composeValue() reads 12-hour segments as hour % 12 + (pm ? 12 : 0).

Fix

  • fieldsFromValue(v, is12) stores the hour as 1–12 + dayPeriod in 12-hour mode (midnight → 12 AM, noon → 12 PM). Used for the initial value, external controlled syncs, and the anchor, so ArrowUp on an empty hour after noon no longer seeds an out-of-range 18.
  • If the hour cycle flips on a mounted field (hourCycle prop or a locale change that flips the default), the stored segments are re-encoded during render. The composed value is unchanged, so onChange doesn't fire. Half-typed hours convert too.
  • Docs: added the missing granularity / hourCycle rows to the DatePicker props table.

Verification

  • 11 new regression tests across date-field.test.tsx and date-range-picker.test.tsx. Against the old hook, 9 fail (the 00:00 minute-edit case passes there by coincidence, since 0 % 12 is AM); without the cycle-change conversion, exactly the 3 switch tests fail.
  • Browser (vite-app showcase, temporary demo not committed): 18:00 → 06:00 PM; minute ArrowUp → 18:01; toggling 12↔24 shows 18:01 / 06:01 PM; a/p on AM/PM → 06:01 / 18:01.
  • Local: fmt, lint, type-check, test, build, docs:check all pass.

🤖 Generated with Claude Code

fieldsFromValue copied the 0-23 hour straight into the segments and never
set dayPeriod, while composeValue reads 12-hour segments as
`hour % 12 + (pm ? 12 : 0)`. 18:00 showed as "18:00 AM" and any edit
saved it as 06:xx. Split the hour into 1-12 + dayPeriod in 12-hour mode,
and re-encode stored segments when the hour cycle flips on a mounted
field (hourCycle prop or locale change).

Refs tailor-inc/platform-planning#2039

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@interacsean

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Review completed successfully!

Code review complete for PR #586: reviewed changed package implementation under packages/core, checked prior PR review threads/comments, and found no actionable High/Medium/Low package issues to flag. No GitHub write was needed because there were no inline findings to post.

Generated by Code Review for #586

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Code Metrics Report

main (529b3ac) #586 (1bc7d88) +/-
Coverage 87.6% 87.9% +0.3%
Test Execution Time 2m14s 2m19s +5s
Details
  |                     | main (529b3ac) | #586 (1bc7d88) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          87.6% |          87.9% | +0.3% |
  |   Files             |            206 |            206 |     0 |
  |   Lines             |           6090 |           6097 |    +7 |
+ |   Covered           |           5335 |           5364 |   +29 |
- | Test Execution Time |          2m14s |          2m19s |   +5s |

Code coverage of files in pull request scope (89.5% → 94.6%, patch 93.3%)

Files Coverage +/- Patch Coverage Status
packages/core/src/components/date-field/date-field.tsx 100.0% 0.0% - modified
packages/core/src/components/date-field/date-input-group.tsx 84.4% +2.9% - affected
packages/core/src/components/date-field/date-range-picker.tsx 97.7% 0.0% - modified
packages/core/src/components/date-field/use-date-field-state.ts 96.8% +10.3% 93.3% modified

Reported by octocov

@interacsean
interacsean marked this pull request as ready for review October 8, 2026 23:34
@interacsean
interacsean requested a review from a team as a code owner October 8, 2026 23:34
@interacsean
interacsean merged commit 4c366d1 into main Oct 9, 2026
7 checks passed
@interacsean
interacsean deleted the fix/2039-date-field-12-hour-pm branch October 9, 2026 04:23
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.

2 participants