Skip to content

feat(react-timepicker-preview): add time utilities - #36812

Open
Victor Genaev (mainframev) wants to merge 1 commit into
masterfrom
timepicker-preview/time-utils
Open

Victor Genaev (mainframev) wants to merge 1 commit into
masterfrom
timepicker-preview/time-utils

Conversation

@mainframev

@mainframev Victor Genaev (mainframev) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #36811 scaffold (merged) → #36845 spec → #36812 time utilities → #36813 TimePicker → #36814 headless TimePicker

New Behavior

Ports the time math from react-timepicker-compat into src/utils together with its tests: option generation, start/end anchors, formatting, and parsing/validation of time strings.

Types that were internal in compat (Hour, TimeFormatOptions, TimePickerOption, TimeStringValidationResult, TimePickerErrorType) move to utils/types.ts. They become public together with the component in #36813

@github-actions

Copy link
Copy Markdown

Pull request demo site: URL

"compilerOptions": {
"noEmit": false,
"lib": ["ES2019", "dom"],
"lib": ["ES2019", "dom", "ES2020.Intl"],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same as in current compat package, needed because of the hourCycle option in formatDateToTimeString

@mainframev
Victor Genaev (mainframev) removed this pull request from stack #36815 October 5, 2026 09:26
@mainframev
Victor Genaev (mainframev) added this pull request to stack #36832 October 5, 2026 09:26
Base automatically changed from timepicker-preview/scaffold to master October 7, 2026 10:00
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

📊 Bundle size report

✅ No changes found

@mainframev
Victor Genaev (mainframev) removed this pull request from stack #36832 October 7, 2026 10:54
@mainframev
Victor Genaev (mainframev) changed the base branch from master to timepicker-preview/spec October 7, 2026 10:55
@mainframev
Victor Genaev (mainframev) added this pull request to stack #36846 October 7, 2026 10:55
@mainframev
Victor Genaev (mainframev) force-pushed the timepicker-preview/time-utils branch 3 times, most recently from 9283fb6 to d22429e Compare October 8, 2026 14:59
@mainframev
Victor Genaev (mainframev) removed this pull request from stack #36846 October 8, 2026 15:00
@mainframev
Victor Genaev (mainframev) added this pull request to stack #36857 October 8, 2026 15:00
@mainframev
Victor Genaev (mainframev) removed this pull request from stack #36857 October 8, 2026 15:21
@mainframev
Victor Genaev (mainframev) added this pull request to stack #36858 October 8, 2026 15:22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 more comments, one is quite an odd edge case

Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
Base automatically changed from timepicker-preview/spec to master October 20, 2026 10:12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The main correctness issue is that localized formatter output cannot always be parsed back. I also suggest sharing the Intl formatter/configuration between formatting and parsing. Separately, the tree-shakeable Temporal function API is worth evaluating for DST resolution, provided we measure the actual bundle impact and verify compatibility; that is a non-blocking design suggestion, not a requirement to add a polyfill in this PR.

Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
Comment thread packages/react-components/react-timepicker-preview/library/src/utils/timeMath.ts Outdated
@mainframev
Victor Genaev (mainframev) force-pushed the timepicker-preview/time-utils branch 2 times, most recently from 80b15e9 to 220b752 Compare October 21, 2026 14:24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've left a couple comments on edge cases.

Let me know if you think they're relevant, or if they are too specific and out of scope

text
.replace(BIDI_MARKS, '')
.replace(NO_BREAK_SPACES, ' ')
.replace(/./g, char => digits.get(char) ?? char);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we use Unicode-aware matching (/./gu) when normalizing digits? In an ff-Adlm runtime, our formatter produces 𞥑𞥔:𞥓𞥐:𞥔𞥕 for 14:30:45, but parsing it returns invalid-input: /./g splits each digit’s surrogate pair before looking it up in the map. That means users cannot commit the localized time we display. Could we add an Adlam round-trip test too?

case 'dayPeriod':
return `(?<dayPeriod>${dayPeriods})`;
case 'literal':
return value.trim() ? `(?::|${escapeRegExp(value)})` : value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we distinguish separators between fields from trailing unit labels? With fr-CA and seconds enabled, 14:30:45 is rejected, but 14:30:45: succeeds because the trailing " s" becomes a required (?::| s) match. Could we accept the documented colon-separated form without requiring a suffix, retain support for 14 h 30 min 45 s, and cover both forms in a regression test?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants