Skip to content

Commit 2e866af

Browse files
fix(adoption-insights): update date formatting (#1948)
* fix(adoption-insights): update date formatting
1 parent aed6beb commit 2e866af

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-adoption-insights': patch
3+
---
4+
5+
Updated to 4-digit year format for all dates

workspaces/adoption-insights/plugins/adoption-insights/src/utils/__tests__/utils.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ describe('getXAxisformat', () => {
181181
});
182182

183183
it('should format daily dates correctly', () => {
184-
expect(getXAxisformat('2025-03-01', 'daily')).toMatch(/Mar \d{1,2}, \d{2}/);
184+
expect(getXAxisformat('2025-03-01', 'daily')).toMatch(/Mar \d{1,2}, \d{4}/);
185185
});
186186

187187
it('should format weekly dates correctly', () => {
188-
expect(getXAxisformat('2025-03-02', 'daily')).toMatch(/Mar \d{1,2}, \d{2}/);
188+
expect(getXAxisformat('2025-03-02', 'daily')).toMatch(/Mar \d{1,2}, \d{4}/);
189189
});
190190

191191
it('should format monthly dates correctly', () => {
@@ -199,12 +199,12 @@ describe('getXAxisformat', () => {
199199
// Test cases for the +00 timezone format fix
200200
it('should handle +00 timezone format correctly for daily grouping', () => {
201201
const result = getXAxisformat('2025-09-29T00:00:00+00', 'daily');
202-
expect(result).toMatch(/Sep \d{1,2}, \d{2}/);
202+
expect(result).toMatch(/Sep \d{1,2}, \d{4}/);
203203
});
204204

205205
it('should handle +00 timezone format correctly for weekly grouping', () => {
206206
const result = getXAxisformat('2025-09-29T00:00:00+00', 'weekly');
207-
expect(result).toMatch(/Sep \d{1,2}, \d{2}/);
207+
expect(result).toMatch(/Sep \d{1,2}, \d{4}/);
208208
});
209209

210210
it('should handle +00 timezone format correctly for monthly grouping', () => {
@@ -219,7 +219,7 @@ describe('getXAxisformat', () => {
219219

220220
it('should handle Z timezone format (should still work)', () => {
221221
const result = getXAxisformat('2025-10-01T03:43:36.535Z', 'daily');
222-
expect(result).toMatch(/Oct \d{1,2}, \d{2}/);
222+
expect(result).toMatch(/Oct \d{1,2}, \d{4}/);
223223
});
224224
});
225225

@@ -236,14 +236,14 @@ describe('getLastUsedDay', () => {
236236

237237
it('should return formatted date for older dates', () => {
238238
expect(getLastUsedDay('2025-02-15T00:00:00Z')).toMatch(
239-
/Feb \d{1,2}, \d{2}/,
239+
/Feb \d{1,2}, \d{4}/,
240240
);
241241
});
242242

243243
// Test cases for the +00 timezone format fix
244244
it('should handle +00 timezone format correctly for older dates', () => {
245245
const result = getLastUsedDay('2025-02-15T00:00:00+00');
246-
expect(result).toMatch(/Feb \d{1,2}, \d{2}/);
246+
expect(result).toMatch(/Feb \d{1,2}, \d{4}/);
247247
});
248248

249249
it('should handle +00 timezone format correctly for recent dates', () => {
@@ -253,13 +253,13 @@ describe('getLastUsedDay', () => {
253253
const pastDateString = pastDate.toISOString().replace('Z', '+00');
254254

255255
const result = getLastUsedDay(pastDateString);
256-
expect(result).toMatch(/\w{3} \d{1,2}, \d{2}/);
256+
expect(result).toMatch(/\w{3} \d{1,2}, \d{4}/);
257257
});
258258

259259
it('should handle Z timezone format (should still work)', () => {
260260
// Use a date that's definitely in the past to avoid "Today" logic
261261
const result = getLastUsedDay('2025-02-15T03:43:36.535Z');
262-
expect(result).toMatch(/Feb \d{1,2}, \d{2}/);
262+
expect(result).toMatch(/Feb \d{1,2}, \d{4}/);
263263
});
264264
});
265265

workspaces/adoption-insights/plugins/adoption-insights/src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const formatDate = (
7474
* @param locale - User's language preference
7575
*/
7676
export const formatShortDate = (date: Date, locale?: string) =>
77-
formatDate(date, { year: '2-digit', month: 'short', day: 'numeric' }, locale);
77+
formatDate(date, { year: 'numeric', month: 'short', day: 'numeric' }, locale);
7878

7979
/**
8080
* Format date in long format: "January 15, 2024"

0 commit comments

Comments
 (0)