Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/generate/dateFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
15 changes: 15 additions & 0 deletions tests/generate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Comment thread
daedalus28 marked this conversation as resolved.
Outdated

// 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);
});
});
Loading