Add scheduled automatic content drafts with Codex and image automation
This commit is contained in:
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user