Notifications corrections
This commit is contained in:
parent
c5295179f9
commit
7797c77639
@ -82,7 +82,7 @@ export function useTaskNotifications() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Helper function to parse date correctly (handles Leantime dates with Z)
|
// Helper function to parse date correctly (handles Leantime dates with Z)
|
||||||
const parseTaskDate = (dateStr: string | null): Date | null => {
|
const parseTaskDate = (dateStr: string | null, taskId?: string, taskTitle?: string): Date | null => {
|
||||||
if (!dateStr) return null;
|
if (!dateStr) return null;
|
||||||
|
|
||||||
// Leantime dates with 'Z' are actually local time stored as UTC
|
// Leantime dates with 'Z' are actually local time stored as UTC
|
||||||
@ -93,7 +93,7 @@ export function useTaskNotifications() {
|
|||||||
const utcDate = new Date(dateStr);
|
const utcDate = new Date(dateStr);
|
||||||
// Extract components from UTC date and create local date
|
// Extract components from UTC date and create local date
|
||||||
// This assumes the UTC date actually represents local time
|
// This assumes the UTC date actually represents local time
|
||||||
return new Date(
|
const parsedDate = new Date(
|
||||||
utcDate.getUTCFullYear(),
|
utcDate.getUTCFullYear(),
|
||||||
utcDate.getUTCMonth(),
|
utcDate.getUTCMonth(),
|
||||||
utcDate.getUTCDate(),
|
utcDate.getUTCDate(),
|
||||||
@ -102,6 +102,23 @@ export function useTaskNotifications() {
|
|||||||
utcDate.getUTCSeconds(),
|
utcDate.getUTCSeconds(),
|
||||||
utcDate.getUTCMilliseconds()
|
utcDate.getUTCMilliseconds()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log('[useTaskNotifications] 📅 Parsing Leantime date (Z -> local)', {
|
||||||
|
taskId,
|
||||||
|
taskTitle,
|
||||||
|
rawDate: dateStr,
|
||||||
|
utcComponents: {
|
||||||
|
year: utcDate.getUTCFullYear(),
|
||||||
|
month: utcDate.getUTCMonth() + 1,
|
||||||
|
day: utcDate.getUTCDate(),
|
||||||
|
hour: utcDate.getUTCHours(),
|
||||||
|
minute: utcDate.getUTCMinutes(),
|
||||||
|
},
|
||||||
|
parsedLocal: parsedDate.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }),
|
||||||
|
parsedISO: parsedDate.toISOString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return parsedDate;
|
||||||
} else if (dateStr.includes('T')) {
|
} else if (dateStr.includes('T')) {
|
||||||
// ISO format without Z - treat as local time
|
// ISO format without Z - treat as local time
|
||||||
return new Date(dateStr);
|
return new Date(dateStr);
|
||||||
@ -132,7 +149,7 @@ export function useTaskNotifications() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse the notification date
|
// Parse the notification date
|
||||||
const notificationDate = parseTaskDate(task.dateToFinish);
|
const notificationDate = parseTaskDate(task.dateToFinish, task.id, task.headline);
|
||||||
|
|
||||||
if (!notificationDate || isNaN(notificationDate.getTime())) {
|
if (!notificationDate || isNaN(notificationDate.getTime())) {
|
||||||
console.log('[useTaskNotifications] ⏭️ Task has no valid date', {
|
console.log('[useTaskNotifications] ⏭️ Task has no valid date', {
|
||||||
@ -148,24 +165,43 @@ export function useTaskNotifications() {
|
|||||||
const timeUntilNotificationMinutes = Math.round(timeUntilNotification / 1000 / 60);
|
const timeUntilNotificationMinutes = Math.round(timeUntilNotification / 1000 / 60);
|
||||||
const timeUntilNotificationSeconds = Math.round(timeUntilNotification / 1000);
|
const timeUntilNotificationSeconds = Math.round(timeUntilNotification / 1000);
|
||||||
|
|
||||||
// Notification window: within 2 minutes of the notification time (1 minute before to 1 minute after)
|
// Check if task is due today
|
||||||
// This allows catching tasks that are due now or just became due
|
const today = new Date();
|
||||||
const notificationWindow = 60 * 1000; // 1 minute
|
const isDueToday =
|
||||||
const inNotificationWindow =
|
notificationDate.getFullYear() === today.getFullYear() &&
|
||||||
timeUntilNotification >= -notificationWindow &&
|
notificationDate.getMonth() === today.getMonth() &&
|
||||||
timeUntilNotification <= notificationWindow;
|
notificationDate.getDate() === today.getDate();
|
||||||
|
|
||||||
|
// Notification window logic:
|
||||||
|
// - For tasks due today but already past due: notify if within 24 hours after due time
|
||||||
|
// - For tasks due today but not yet due: notify if within ±1 minute of due time
|
||||||
|
// - For future tasks: notify if within ±1 minute of due time
|
||||||
|
let inNotificationWindow = false;
|
||||||
|
|
||||||
|
if (isDueToday && timeUntilNotification < 0) {
|
||||||
|
// Task is due today but already past due - notify if within 24 hours after
|
||||||
|
const hoursPastDue = Math.abs(timeUntilNotificationMinutes) / 60;
|
||||||
|
inNotificationWindow = hoursPastDue <= 24;
|
||||||
|
} else {
|
||||||
|
// Task is due today (not yet due) or future - notify if within ±1 minute
|
||||||
|
const notificationWindow = 60 * 1000; // 1 minute
|
||||||
|
inNotificationWindow =
|
||||||
|
timeUntilNotification >= -notificationWindow &&
|
||||||
|
timeUntilNotification <= notificationWindow;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('[useTaskNotifications] ⏰ Checking task', {
|
console.log('[useTaskNotifications] ⏰ Checking task', {
|
||||||
id: task.id,
|
id: task.id,
|
||||||
title: task.headline,
|
title: task.headline,
|
||||||
source: task.source,
|
source: task.source,
|
||||||
rawDate: task.dateToFinish,
|
rawDate: task.dateToFinish,
|
||||||
notificationDateLocal: notificationDate.toLocaleString('fr-FR'),
|
parsedDateLocal: notificationDate.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }),
|
||||||
notificationDateISO: notificationDate.toISOString(),
|
parsedDateISO: notificationDate.toISOString(),
|
||||||
nowLocal: now.toLocaleString('fr-FR'),
|
nowLocal: now.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }),
|
||||||
nowISO: now.toISOString(),
|
nowISO: now.toISOString(),
|
||||||
timeUntilNotificationMinutes,
|
timeUntilNotificationMinutes,
|
||||||
timeUntilNotificationSeconds,
|
timeUntilNotificationSeconds,
|
||||||
|
isDueToday,
|
||||||
inWindow: inNotificationWindow,
|
inWindow: inNotificationWindow,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user