Add scheduled automatic content drafts with Codex and image automation

This commit is contained in:
chaloemphong
2026-11-25 21:11:38 +07:00
parent 55235718c3
commit dd42b81639
13 changed files with 444 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
/** Weekly slots in Asia/Bangkok (UTC+7, no daylight saving), strictly after now. */
export function nextContentRun(weekdays: number[], times: string[], now = new Date()): Date {
const offset = 7 * 60 * 60_000;
const local = new Date(now.getTime() + offset);
for (let day = 0; day <= 7; day++) {
const midnight = Date.UTC(local.getUTCFullYear(), local.getUTCMonth(), local.getUTCDate() + day);
if (!weekdays.includes(new Date(midnight).getUTCDay())) continue;
for (const time of [...times].sort()) {
const [hours, minutes] = time.split(":").map(Number);
const candidate = new Date(midnight + (hours * 60 + minutes) * 60_000 - offset);
if (candidate > now) return candidate;
}
}
throw new Error("No valid weekly content slot");
}