widget leantime refactor

This commit is contained in:
alma 2026-01-15 23:02:02 +01:00
parent 9ff8c3ca7a
commit 6cce6d4269

View File

@ -221,8 +221,11 @@ async function fetchTwentyTasks(): Promise<TwentyTask[]> {
}); });
// Filter client-side for overdue tasks (dueAt < today) and not completed (status !== 'Done') // Filter client-side for overdue tasks (dueAt < today) and not completed (status !== 'Done')
const todayForFilter = new Date(); // Use local date for comparison to avoid timezone issues
todayForFilter.setHours(0, 0, 0, 0); const now = new Date();
const todayYear = now.getFullYear();
const todayMonth = now.getMonth();
const todayDay = now.getDate();
const tasks: TwentyTask[] = allTasks const tasks: TwentyTask[] = allTasks
.filter((task: TwentyTask) => { .filter((task: TwentyTask) => {
@ -237,15 +240,24 @@ async function fetchTwentyTasks(): Promise<TwentyTask[]> {
return false; // Exclude tasks without due date return false; // Exclude tasks without due date
} }
// Parse the due date and compare dates (not times)
// Use local date comparison to avoid timezone issues
const taskDueDate = new Date(task.dueAt); const taskDueDate = new Date(task.dueAt);
taskDueDate.setHours(0, 0, 0, 0); // Get local date components (year, month, day) ignoring time
const taskYear = taskDueDate.getFullYear();
const taskMonth = taskDueDate.getMonth();
const taskDay = taskDueDate.getDate();
const isOverdue = taskDueDate < todayForFilter; // Compare dates: task is overdue if its date is before today's date
logger.debug('[TWENTY_CRM_TASKS] Task date check', { const isOverdue = taskYear < todayYear ||
(taskYear === todayYear && taskMonth < todayMonth) ||
(taskYear === todayYear && taskMonth === todayMonth && taskDay < todayDay);
logger.error('[TWENTY_CRM_TASKS] Task date check', {
id: task.id, id: task.id,
dueAt: task.dueAt, dueAt: task.dueAt,
taskDueDate: taskDueDate.toISOString(), taskDate: `${taskYear}-${String(taskMonth + 1).padStart(2, '0')}-${String(taskDay).padStart(2, '0')}`,
today: todayForFilter.toISOString(), todayDate: `${todayYear}-${String(todayMonth + 1).padStart(2, '0')}-${String(todayDay).padStart(2, '0')}`,
isOverdue, isOverdue,
}); });