Merge pull request #348 from reuters-graphics/mf-prettify-date-fix

Quick fix: prettifyDate
This commit is contained in:
Minami 2025-08-12 09:59:21 -04:00 committed by GitHub
commit b3994e6f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@reuters-graphics/graphics-components': patch
---
Fixes prettifyDate to format Aug, Oct-Dec

View file

@ -114,6 +114,18 @@ describe('Utils tests', () => {
const unformattedSept = 'Sep. 2025';
const formattedSept = 'Sept. 2025';
expect(prettifyDate(unformattedSept)).toBe(formattedSept);
const unformattedOct = 'Oct. 2025';
const formattedOct = 'Oct. 2025';
expect(prettifyDate(unformattedOct)).toBe(formattedOct);
const unformattedNov = 'Nov 2025';
const formattedNov = 'Nov. 2025';
expect(prettifyDate(unformattedNov)).toBe(formattedNov);
const unformattedDec = 'DEC 2025';
const formattedDec = 'Dec. 2025';
expect(prettifyDate(unformattedDec)).toBe(formattedDec);
});
it('should fix spacing between time and am/pm', () => {
@ -133,9 +145,17 @@ describe('Utils tests', () => {
const formattedJune = 'June 1, 2023, 10:00 a.m.';
expect(prettifyDate(unformattedJune)).toBe(formattedJune);
const unformattedAug = 'aug 1, 2023, 10:00PM';
const formattedAug = 'Aug. 1, 2023, 10:00 p.m.';
expect(prettifyDate(unformattedAug)).toBe(formattedAug);
const unformattedSept = 'sep. 1, 2023, 10:00PM';
const formattedSept = 'Sept. 1, 2023, 10:00 p.m.';
expect(prettifyDate(unformattedSept)).toBe(formattedSept);
const unformattedOct = 'oct 1, 2023, 10:00PM';
const formattedOct = 'Oct. 1, 2023, 10:00 p.m.';
expect(prettifyDate(unformattedOct)).toBe(formattedOct);
});
it('should work with lower or upper case', () => {
@ -154,5 +174,9 @@ describe('Utils tests', () => {
const unformattedJune = 'JUN. 1, 2023, 10:00AM';
const formattedJune = 'June 1, 2023, 10:00 a.m.';
expect(prettifyDate(unformattedJune)).toBe(formattedJune);
const unformattedAug = 'AUG. 1, 2023, 10:00PM';
const formattedAug = 'Aug. 1, 2023, 10:00 p.m.';
expect(prettifyDate(unformattedAug)).toBe(formattedAug);
});
});

View file

@ -52,7 +52,11 @@ export const prettifyDate = (input: string) => {
apr: 'April',
jun: 'June',
jul: 'July',
aug: 'Aug.',
sep: 'Sept.',
oct: 'Oct.',
nov: 'Nov.',
dec: 'Dec.',
};
// If the key in conversions is found in the input (case insensitive), replace it with the corresponding value