import { fromKstInput, kstFields } from '../../src/ui/time.ts'; import { THREADS } from '../../src/constants/threads.ts'; export function nextRunAt(now: Date, completedDate?: string): Date { const date = kstFields(now).date; const today = fromKstInput(date, THREADS.scheduleHourKst * 60); if (completedDate === date) { const tomorrow = new Date(+fromKstInput(date, 12 * 60) + 86_400_000); return fromKstInput(kstFields(tomorrow).date, THREADS.scheduleHourKst * 60); } return +now < +today ? today : now; }