Skip to content

Commit 0405152

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

File tree

1 file changed

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

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ 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+
680684
switch (timeScale) {
681685
case 'second':
682686
difference = (adjusted_date.getTime() - startDate.getTime()) / msInSecond;
@@ -697,9 +701,10 @@ export function computeCountToTimeScale(
697701
difference =
698702
(adjusted_date.getFullYear() - startDate.getFullYear()) * 12 +
699703
(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();
704+
705+
// Calculate fractional difference by normalizing day progress within each specific month
706+
// This handles variable month lengths (28/29/30/31 days) correctly
707+
difference += adjusted_date.getDate() / adjustedDaysInMonth - startDate.getDate() / startDaysInMonth;
703708
break;
704709
case 'quarter':
705710
difference =

0 commit comments

Comments
 (0)