Skip to content

Commit 9e601f0

Browse files
committed
fix(gantt): correct month difference calculation for variable month lengths
1 parent ab95a6b commit 9e601f0

File tree

1 file changed

+9
-3
lines changed
  • packages/vtable-gantt/src/tools

1 file changed

+9
-3
lines changed

packages/vtable-gantt/src/tools/util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ export function computeCountToTimeScale(
677677

678678
let difference: number;
679679
const adjusted_date = new Date(date.getTime() + diffMS);
680+
681+
const startDaysInMonth = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0).getDate();
682+
const adjustedDaysInMonth = new Date(adjusted_date.getFullYear(), adjusted_date.getMonth() + 1, 0).getDate();
683+
console.log(startDaysInMonth, 'startDaysInMonth');
684+
680685
switch (timeScale) {
681686
case 'second':
682687
difference = (adjusted_date.getTime() - startDate.getTime()) / msInSecond;
@@ -697,9 +702,10 @@ export function computeCountToTimeScale(
697702
difference =
698703
(adjusted_date.getFullYear() - startDate.getFullYear()) * 12 +
699704
(adjusted_date.getMonth() - startDate.getMonth());
700-
difference +=
701-
(adjusted_date.getDate() - startDate.getDate()) /
702-
new Date(adjusted_date.getFullYear(), adjusted_date.getMonth() + 1, 0).getDate();
705+
706+
// Calculate fractional difference by normalizing day progress within each specific month
707+
// This handles variable month lengths (28/29/30/31 days) correctly
708+
difference += adjusted_date.getDate() / adjustedDaysInMonth - startDate.getDate() / startDaysInMonth;
703709
break;
704710
case 'quarter':
705711
difference =

0 commit comments

Comments
 (0)