Bug
When using the date-fns generateConfig with use12Hours, the picker crashes with:
RangeError: Format string contains an unescaped latin alphabet character `A`
This happens because use12Hours causes rc-picker to internally inject uppercase A (moment.js AM/PM token) into the format string. The localeParse function in src/generate/dateFns.ts converts other moment tokens to date-fns equivalents but doesn't handle A → a:
const localeParse = (format: string) =>
format
.replace(/Y/g, 'y')
.replace(/D/g, 'd')
.replace(/gggg/, 'yyyy')
.replace(/g/g, 'G')
.replace(/([Ww])o/g, 'wo');
// missing: .replace(/A/g, 'a')
date-fns uses lowercase a for AM/PM (hh:mm:ss a), while moment.js uses uppercase A. Since localeParse already handles the other moment → date-fns conversions, this one was likely just missed.
Suggested fix
Add .replace(/A/g, 'a') to localeParse:
const localeParse = (format: string) =>
format
.replace(/Y/g, 'y')
.replace(/D/g, 'd')
.replace(/gggg/, 'yyyy')
.replace(/g/g, 'G')
.replace(/([Ww])o/g, 'wo')
.replace(/A/g, 'a');
Reproduction
import dateFnsGenerateConfig from '@rc-component/picker/es/generate/dateFns'
import generatePicker from 'antd/es/date-picker/generatePicker'
const DatePicker = generatePicker<Date>(dateFnsGenerateConfig)
// This crashes:
<DatePicker showTime use12Hours />
Versions
@rc-component/picker: 1.9.1
date-fns: 4.1.0
antd: 6.3.5
Bug
When using the date-fns
generateConfigwithuse12Hours, the picker crashes with:This happens because
use12Hourscauses rc-picker to internally inject uppercaseA(moment.js AM/PM token) into the format string. ThelocaleParsefunction insrc/generate/dateFns.tsconverts other moment tokens to date-fns equivalents but doesn't handleA→a:date-fns uses lowercase
afor AM/PM (hh:mm:ss a), while moment.js uses uppercaseA. SincelocaleParsealready handles the other moment → date-fns conversions, this one was likely just missed.Suggested fix
Add
.replace(/A/g, 'a')tolocaleParse:Reproduction
Versions
@rc-component/picker: 1.9.1date-fns: 4.1.0antd: 6.3.5