Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-24 13:59:15 +00:00
co-authored by renee-png
parent c7ef65500a
commit 8a7eefb3ec
+15 -3
View File
@@ -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<string | nu
if (existing) return existing.id;
const baseDate = task.completed_at ? new Date(task.completed_at) : new Date();
const dueDate = format(addDays(baseDate, nextTpl.days_from_start ?? 0), "yyyy-MM-dd");
const dueDate = toUTCDateString(addDays(baseDate, nextTpl.days_from_start ?? 0));
const { data: created, error } = await supabase
.from("tasks")
@@ -129,7 +141,7 @@ export async function spawnNextCollectionWorkflowTask(
if (existing) return existing.id;
const baseDate = ct.done_at ? new Date(ct.done_at) : new Date();
const dueDate = format(addDays(baseDate, nextTpl.days_from_start ?? 0), "yyyy-MM-dd");
const dueDate = toUTCDateString(addDays(baseDate, nextTpl.days_from_start ?? 0));
const { data: created, error } = await supabase
.from("collection_tasks")