-
Notifications
You must be signed in to change notification settings - Fork 13.5k
regression: moment compatibility for admin date format settings
#40304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dionisio-bot
merged 6 commits into
release-8.4.0
from
fix/moment-bracket-literal-date-format
Apr 28, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
61f249b
fix: enhance momentFormatToDateFns to handle literal date formats
dougfabris b11f1c7
test: add unit tests for momentFormatToDateFns and formatDate functions
dougfabris e580b36
fix: enhance momentFormatToDateFns and formatDate to handle edge case…
dougfabris c6fc335
fix: enhance momentFormatToDateFns to support additional date formatt…
dougfabris 22faf04
chore: tweak outdated token
dougfabris 2abfd2f
fix: update momentFormatToDateFns to correctly handle AM/PM casing
dougfabris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { formatDate, momentFormatToDateFns } from './dateFormat'; | ||
|
|
||
| describe('momentFormatToDateFns', () => { | ||
| it('maps locale tokens', () => { | ||
| expect(momentFormatToDateFns('L')).toBe('P'); | ||
| expect(momentFormatToDateFns('LT')).toBe('p'); | ||
| expect(momentFormatToDateFns('LTS')).toBe('pp'); | ||
| expect(momentFormatToDateFns('LL')).toBe('PPP'); | ||
| expect(momentFormatToDateFns('LLL')).toBe('PPP p'); | ||
| expect(momentFormatToDateFns('LLLL')).toBe('EEEE, PPP p'); | ||
| }); | ||
|
|
||
| it('maps common tokens', () => { | ||
| expect(momentFormatToDateFns('YYYY-MM-DD HH:mm:ss')).toBe('yyyy-MM-dd HH:mm:ss'); | ||
| expect(momentFormatToDateFns('MMMM Do YYYY, h:mm:ss a')).toBe('MMMM do yyyy, h:mm:ss a'); | ||
| }); | ||
|
|
||
| it('translates moment [literal] escape to date-fns single-quoted literal', () => { | ||
| expect(momentFormatToDateFns('[Today at] LT')).toBe("'Today at' p"); | ||
| expect(momentFormatToDateFns('[Session started at] HH:mm [on] LL')).toBe("'Session started at' HH:mm 'on' PPP"); | ||
| }); | ||
|
|
||
| it("escapes embedded single quotes inside literals as ''", () => { | ||
| expect(momentFormatToDateFns("[it's] LT")).toBe("'it''s' p"); | ||
| }); | ||
|
|
||
| it('drops empty literal blocks since date-fns has no empty-string syntax', () => { | ||
| // In date-fns, '' represents a literal apostrophe, not an empty string. | ||
| expect(momentFormatToDateFns('[] LT')).toBe(' p'); | ||
| }); | ||
|
|
||
| it('quotes letters that are not Moment tokens (T in ISO 8601 separator)', () => { | ||
| // In Moment, T is a literal; in date-fns T = ms timestamp. Must quote. | ||
| expect(momentFormatToDateFns('YYYY-MM-DDTHH:mm:ss')).toBe("yyyy-MM-dd'T'HH:mm:ss"); | ||
| }); | ||
|
|
||
| it('maps Moment timezone offset tokens to date-fns equivalents', () => { | ||
| expect(momentFormatToDateFns('Z')).toBe('xxx'); | ||
| expect(momentFormatToDateFns('ZZ')).toBe('xx'); | ||
| expect(momentFormatToDateFns('Z ZZ')).toBe('xxx xx'); | ||
| expect(momentFormatToDateFns('LT Z')).toBe('p xxx'); | ||
| expect(momentFormatToDateFns('YYYY-MM-DDTHH:mm:ssZ')).toBe("yyyy-MM-dd'T'HH:mm:ssxxx"); | ||
| }); | ||
| }); | ||
|
|
||
| describe('formatDate', () => { | ||
| const sample = new Date('2026-04-24T20:30:45'); | ||
|
|
||
| it('formats literal blocks with locale tokens without throwing', () => { | ||
| expect(() => formatDate(sample, '[Today at] LT')).not.toThrow(); | ||
| expect(formatDate(sample, '[Today at] LT')).toMatch(/^Today at /); | ||
| }); | ||
|
|
||
| it('formats date with year-month-day token string', () => { | ||
| expect(formatDate(sample, 'YYYY-MM-DD')).toBe('2026-04-24'); | ||
| }); | ||
|
|
||
| it('keeps the ISO 8601 T as a literal instead of inserting a ms timestamp', () => { | ||
| expect(formatDate(sample, 'YYYY-MM-DDTHH:mm:ss')).toBe('2026-04-24T20:30:45'); | ||
| }); | ||
|
|
||
| it('does not throw on Moment timezone tokens', () => { | ||
| expect(() => formatDate(sample, 'LT Z')).not.toThrow(); | ||
| expect(() => formatDate(sample, 'Z ZZ')).not.toThrow(); | ||
| expect(() => formatDate(sample, 'YYYY-MM-DDTHH:mm:ssZ')).not.toThrow(); | ||
| }); | ||
|
|
||
| it('falls back instead of crashing on a malformed format', () => { | ||
| // Unterminated bracket — translator buffers but date-fns may still refuse. | ||
| expect(() => formatDate(sample, '[unterminated')).not.toThrow(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.