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