From 4b6c2d7805a2d85c0702b3ee9869aaff722a276a Mon Sep 17 00:00:00 2001 From: Shaun Hamilton Date: Thu, 27 Nov 2025 15:16:25 +0200 Subject: [PATCH] fix(api): handle string numbers in normalizeDate (#64188) --- api/src/utils/normalize.test.ts | 4 ++++ api/src/utils/normalize.ts | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/src/utils/normalize.test.ts b/api/src/utils/normalize.test.ts index ee0267dda04..831eaa2dcc3 100644 --- a/api/src/utils/normalize.test.ts +++ b/api/src/utils/normalize.test.ts @@ -193,6 +193,10 @@ describe('normalize', () => { 'Unexpected date value: {"date":"123"}' ); }); + + test('should handle string numbers', () => { + expect(normalizeDate('1696118400000')).toEqual(1696118400000); + }); }); describe('normalizeChallengeType', () => { diff --git a/api/src/utils/normalize.ts b/api/src/utils/normalize.ts index b6d1c422f15..bfad634c34e 100644 --- a/api/src/utils/normalize.ts +++ b/api/src/utils/normalize.ts @@ -76,9 +76,16 @@ export const normalizeDate = (date?: Prisma.JsonValue): number => { typeof date.$date === 'string' ) { return new Date(date.$date).getTime(); - } else { - throw Error('Unexpected date value: ' + JSON.stringify(date)); + } else if (typeof date === 'string') { + const parsed = Number(date); + if (!isNaN(parsed)) { + // Number() handles invalid strings e.g. '2023-10-01T00:00:00Z' + // parseInt() handles floats + return parseInt(String(parsed)); + } } + + throw Error('Unexpected date value: ' + JSON.stringify(date)); }; /**