From cb2f157aede83ae93c994f449264bf4d83dfa576 Mon Sep 17 00:00:00 2001 From: Samuel Greene Date: Fri, 17 Apr 2026 11:02:59 -0700 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20add=20A=20=E2=86=92=20a=20replacemen?= =?UTF-8?q?t=20in=20dateFns=20localeParse=20for=20use12Hours=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When use12Hours is enabled, rc-picker internally injects uppercase A (moment.js AM/PM token) into the format string. date-fns uses lowercase a for AM/PM, so passing A through causes: RangeError: Format string contains an unescaped latin alphabet character `A` localeParse already converts other moment tokens (Y→y, D→d, etc.) but was missing A→a. This adds it. Fixes react-component/picker#964 --- src/generate/dateFns.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/generate/dateFns.ts b/src/generate/dateFns.ts index e77ee1639..5156450bb 100644 --- a/src/generate/dateFns.ts +++ b/src/generate/dateFns.ts @@ -41,7 +41,8 @@ const localeParse = (format: string) => { .replace(/D/g, 'd') .replace(/gggg/, 'yyyy') .replace(/g/g, 'G') - .replace(/([Ww])o/g, 'wo'); + .replace(/([Ww])o/g, 'wo') + .replace(/A/g, 'a'); }; const parse = (text: string, format: string, locale: string) => { From 582a66bfb67b03afaf9f4f979dbe05177dc97073 Mon Sep 17 00:00:00 2001 From: Samuel Greene Date: Sun, 19 Apr 2026 07:39:21 -0700 Subject: [PATCH 2/2] Add test for AM/PM format token conversion in date-fns adapter Verifies that localeParse converts uppercase A (moment-style AM/PM) to lowercase a (date-fns) so that both format() and parse() work correctly with 12-hour time formats. Co-Authored-By: Claude Opus 4.6 --- tests/generate.spec.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/generate.spec.tsx b/tests/generate.spec.tsx index 3c03e660f..086596857 100644 --- a/tests/generate.spec.tsx +++ b/tests/generate.spec.tsx @@ -335,4 +335,19 @@ describe('Generate:date-fns', () => { expect(dateFnsGenerateConfig.locale.getWeekFirstDay('it_IT')).toEqual(1); expect(dateFnsGenerateConfig.locale.getWeekFirstDay('fr_FR')).toEqual(1); }); + + it('format and parse with AM/PM (uppercase A)', () => { + const date = new Date(2000, 0, 1, 14, 30, 0); + + // Format with uppercase A (moment-style) should produce lowercase am/pm output + const formatted = dateFnsGenerateConfig.locale.format('en_US', date, 'YYYY-MM-DD hh:mm:ss A'); + expect(formatted).toEqual('2000-01-01 02:30:00 PM'); + + // Parse with uppercase A should also work without throwing + const parsed = dateFnsGenerateConfig.locale.parse('en_US', '2000-01-01 02:30:00 PM', [ + 'YYYY-MM-DD hh:mm:ss A', + ]); + expect(dateFnsGenerateConfig.getHour(parsed)).toEqual(14); + expect(dateFnsGenerateConfig.getMinute(parsed)).toEqual(30); + }); });