MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / normalizeDate

Function normalizeDate

api/src/utils/normalize.ts:69–89  ·  view source on GitHub ↗
(date?: Prisma.JsonValue)

Source from the content-addressed store, hash-verified

67 * @returns The date as a timestamp number.
68 */
69export const normalizeDate = (date?: Prisma.JsonValue): number => {
70 if (typeof date === 'number') {
71 return date;
72 } else if (
73 date &&
74 typeof date === 'object' &&
75 '$date' in date &&
76 typeof date.$date === 'string'
77 ) {
78 return new Date(date.$date).getTime();
79 } else if (typeof date === 'string') {
80 const parsed = Number(date);
81 if (!isNaN(parsed)) {
82 // Number() handles invalid strings e.g. '2023-10-01T00:00:00Z'
83 // parseInt() handles floats
84 return parseInt(String(parsed));
85 }
86 }
87
88 throw Error('Unexpected date value: ' + JSON.stringify(date));
89};
90
91/**
92 * Normalizes a challenge type value to a number.

Callers 7

normalizeChallengesFunction · 0.85
normalize.test.tsFile · 0.85
updateUserChallengeDataFunction · 0.85
challengeRoutesFunction · 0.85
getFallbackFullStackDateFunction · 0.85
classroomRoutesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected