diff --git a/src/lib/workflow-chain.ts b/src/lib/workflow-chain.ts index 660dedd..ea015b8 100644 --- a/src/lib/workflow-chain.ts +++ b/src/lib/workflow-chain.ts @@ -1,5 +1,17 @@ import { supabase } from "@/integrations/supabase/client"; -import { addDays, format } from "date-fns"; +import { addDays } from "date-fns"; + +/** + * Format a Date as "YYYY-MM-DD" using its UTC components. We do this so that + * a `completed_at` UTC timestamp like 2026-04-24T02:00:00Z (which is still + * Apr 23 in US local time) doesn't shift the computed due_date back a day. + */ +function toUTCDateString(d: Date): string { + const y = d.getUTCFullYear(); + const m = String(d.getUTCMonth() + 1).padStart(2, "0"); + const day = String(d.getUTCDate()).padStart(2, "0"); + return `${y}-${m}-${day}`; +} /** * After a task is marked complete, spawn the next task from its workflow @@ -48,7 +60,7 @@ export async function spawnNextWorkflowTask(taskId: string): Promise