fix: Show next run time correctly for schedules

This commit is contained in:
Kelly
2025-12-12 20:21:15 -07:00
parent 4ea7139ed5
commit dfd36dacf8

View File

@@ -703,6 +703,28 @@ function formatTimeAgo(dateStr: string | null): string {
return `${Math.floor(diff / 86400)}d ago`;
}
function formatNextRun(dateStr: string | null): string {
if (!dateStr) return '-';
const date = new Date(dateStr);
const now = new Date();
const diff = (date.getTime() - now.getTime()) / 1000;
// If in the past, show "overdue"
if (diff < 0) {
const absDiff = Math.abs(diff);
if (absDiff < 60) return 'overdue';
if (absDiff < 3600) return `${Math.floor(absDiff / 60)}m overdue`;
if (absDiff < 86400) return `${Math.floor(absDiff / 3600)}h overdue`;
return `${Math.floor(absDiff / 86400)}d overdue`;
}
// Future time
if (diff < 60) return `in ${Math.round(diff)}s`;
if (diff < 3600) return `in ${Math.floor(diff / 60)}m`;
if (diff < 86400) return `in ${Math.floor(diff / 3600)}h ${Math.floor((diff % 3600) / 60)}m`;
return `in ${Math.floor(diff / 86400)}d ${Math.floor((diff % 86400) / 3600)}h`;
}
export default function TasksDashboard() {
const [tasks, setTasks] = useState<Task[]>([]);
const [counts, setCounts] = useState<TaskCounts | null>(null);
@@ -1235,7 +1257,7 @@ export default function TasksDashboard() {
{schedule.last_run_at ? formatTimeAgo(schedule.last_run_at) : '-'}
</td>
<td className="px-4 py-3 text-sm text-gray-600">
{schedule.next_run_at ? formatTimeAgo(schedule.next_run_at) : '-'}
{schedule.next_run_at ? formatNextRun(schedule.next_run_at) : '-'}
</td>
<td className="px-4 py-3">
<span