mirror of
https://github.com/callumalpass/tasknotes.git
synced 2026-07-22 12:50:26 +00:00
fix: correct all-day event resize duration calculation
FullCalendar's end date for all-day events is exclusive (next day at midnight). When resizing a 2-day all-day task from Jan 15-17, FullCalendar provides: - start: Jan 15 00:00 - end: Jan 18 00:00 (exclusive) The previous calculation treated this as 3 days (4320 minutes) instead of the correct 2 days (2880 minutes), causing tasks to span more days than intended when resized. This fix handles all-day events separately by calculating days directly from the millisecond difference, which already accounts for the exclusive end date from FullCalendar. Fixes both Bases calendar view and AdvancedCalendarView.
This commit is contained in:
parent
abd75f2f07
commit
720a8c153c
5 changed files with 30 additions and 2 deletions
BIN
1759743819.gif
Normal file
BIN
1759743819.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 MiB |
BIN
1759751819.gif
Normal file
BIN
1759751819.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 836 KiB |
BIN
1759752042.gif
Normal file
BIN
1759752042.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
|
|
@ -355,7 +355,21 @@ export function buildTasknotesCalendarViewFactory(plugin: TaskNotesPlugin) {
|
|||
const end = resizeInfo.event.end;
|
||||
|
||||
if (start && end) {
|
||||
const durationMinutes = Math.round((end.getTime() - start.getTime()) / (1000 * 60));
|
||||
let durationMinutes: number;
|
||||
|
||||
if (resizeInfo.event.allDay) {
|
||||
// For all-day events, FullCalendar's end date is exclusive (next day at midnight)
|
||||
// So we need to subtract 1 day to get the actual duration
|
||||
// Example: Jan 15 to Jan 17 (2 days) gives end = Jan 18 00:00
|
||||
const dayDurationMillis = 24 * 60 * 60 * 1000;
|
||||
const daysDuration = Math.round((end.getTime() - start.getTime()) / dayDurationMillis);
|
||||
const minutesPerDay = 60 * 24;
|
||||
durationMinutes = daysDuration * minutesPerDay;
|
||||
} else {
|
||||
// For timed events, calculate duration directly
|
||||
durationMinutes = Math.round((end.getTime() - start.getTime()) / (1000 * 60));
|
||||
}
|
||||
|
||||
await plugin.taskService.updateProperty(taskInfo, "timeEstimate", durationMinutes);
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1447,7 +1447,21 @@ export class AdvancedCalendarView extends ItemView implements OptimizedView {
|
|||
const end = resizeInfo.event.end;
|
||||
|
||||
if (start && end) {
|
||||
const durationMinutes = Math.round((end.getTime() - start.getTime()) / (1000 * 60));
|
||||
let durationMinutes: number;
|
||||
|
||||
if (resizeInfo.event.allDay) {
|
||||
// For all-day events, FullCalendar's end date is exclusive (next day at midnight)
|
||||
// So we need to subtract 1 day to get the actual duration
|
||||
// Example: Jan 15 to Jan 17 (2 days) gives end = Jan 18 00:00
|
||||
const dayDurationMillis = 24 * 60 * 60 * 1000;
|
||||
const daysDuration = Math.round((end.getTime() - start.getTime()) / dayDurationMillis);
|
||||
const minutesPerDay = 60 * 24;
|
||||
durationMinutes = daysDuration * minutesPerDay;
|
||||
} else {
|
||||
// For timed events, calculate duration directly
|
||||
durationMinutes = Math.round((end.getTime() - start.getTime()) / (1000 * 60));
|
||||
}
|
||||
|
||||
await this.plugin.taskService.updateProperty(
|
||||
taskInfo,
|
||||
"timeEstimate",
|
||||
|
|
|
|||
Loading…
Reference in a new issue