diff --git a/apps/web/lib/time.test.ts b/apps/web/lib/time.test.ts index 9b28d12acb..795c7aade3 100644 --- a/apps/web/lib/time.test.ts +++ b/apps/web/lib/time.test.ts @@ -141,5 +141,52 @@ describe("Time Utilities", () => { expect(convertDatesInObject("string")).toBe("string"); expect(convertDatesInObject(123)).toBe(123); }); + + test("should not convert dates in contactAttributes", () => { + const input = { + createdAt: "2024-03-20T15:30:00", + contactAttributes: { + createdAt: "2024-03-20T16:30:00", + email: "test@example.com", + }, + }; + + const result = convertDatesInObject(input); + expect(result.createdAt).toBeInstanceOf(Date); + expect(result.contactAttributes.createdAt).toBe("2024-03-20T16:30:00"); + expect(result.contactAttributes.email).toBe("test@example.com"); + }); + + test("should not convert dates in variables", () => { + const input = { + updatedAt: "2024-03-20T15:30:00", + variables: { + createdAt: "2024-03-20T16:30:00", + userId: "123", + }, + }; + + const result = convertDatesInObject(input); + expect(result.updatedAt).toBeInstanceOf(Date); + expect(result.variables.createdAt).toBe("2024-03-20T16:30:00"); + expect(result.variables.userId).toBe("123"); + }); + + test("should not convert dates in data or meta", () => { + const input = { + createdAt: "2024-03-20T15:30:00", + data: { + createdAt: "2024-03-20T16:30:00", + }, + meta: { + updatedAt: "2024-03-20T17:30:00", + }, + }; + + const result = convertDatesInObject(input); + expect(result.createdAt).toBeInstanceOf(Date); + expect(result.data.createdAt).toBe("2024-03-20T16:30:00"); + expect(result.meta.updatedAt).toBe("2024-03-20T17:30:00"); + }); }); }); diff --git a/apps/web/lib/time.ts b/apps/web/lib/time.ts index 05246760c7..efe8ed2dd7 100644 --- a/apps/web/lib/time.ts +++ b/apps/web/lib/time.ts @@ -160,7 +160,12 @@ export const convertDatesInObject = (obj: T): T => { return obj.map((item) => convertDatesInObject(item)) as unknown as T; } const newObj: any = {}; + const keysToIgnore = new Set(["contactAttributes", "variables", "data", "meta"]); for (const key in obj) { + if (keysToIgnore.has(key)) { + newObj[key] = obj[key]; + continue; + } if ( (key === "createdAt" || key === "updatedAt") && typeof obj[key] === "string" &&