Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Convert dates to standard format

Tim Wilsond5ea1da798e2
diff --git a/apps/web/lib/ai/generate-filters.ts b/apps/web/lib/ai/generate-filters.ts
index 3520625e40..38bad49cc8 100644
--- a/apps/web/lib/ai/generate-filters.ts
+++ b/apps/web/lib/ai/generate-filters.ts
@@ -3,6 +3,7 @@
import { VALID_ANALYTICS_FILTERS } from "@/lib/analytics/constants";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import { anthropic } from "@ai-sdk/anthropic";
+import { parseDateTime } from "@dub/utils";
import { streamObject } from "ai";
import { createStreamableValue } from "ai/rsc";
@@ -23,7 +24,20 @@ export async function generateFilters(prompt: string) {
});
for await (const partialObject of partialObjectStream) {
- stream.update(partialObject);
+ stream.update(
+ Object.fromEntries(
+ Object.entries(partialObject).map(([key, value]) => {
+ if (!["start", "end"].includes(key) || value === null)
+ return [key, value];
+
+ // Convert start and end dates to standard format
+ return [
+ key,
+ value ? parseDateTime(value.toString())?.toISOString() : value,
+ ];
+ }),
+ ),
+ );
}
stream.done();