Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/vtable-gantt/src/tools/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ export function computeCountToTimeScale(

let difference: number;
const adjusted_date = new Date(date.getTime() + diffMS);

const startDaysInMonth = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0).getDate();
const adjustedDaysInMonth = new Date(adjusted_date.getFullYear(), adjusted_date.getMonth() + 1, 0).getDate();

switch (timeScale) {
case 'second':
difference = (adjusted_date.getTime() - startDate.getTime()) / msInSecond;
Expand All @@ -697,9 +701,10 @@ export function computeCountToTimeScale(
difference =
(adjusted_date.getFullYear() - startDate.getFullYear()) * 12 +
(adjusted_date.getMonth() - startDate.getMonth());
difference +=
(adjusted_date.getDate() - startDate.getDate()) /
new Date(adjusted_date.getFullYear(), adjusted_date.getMonth() + 1, 0).getDate();

// Calculate fractional difference by normalizing day progress within each specific month
// This handles variable month lengths (28/29/30/31 days) correctly
difference += adjusted_date.getDate() / adjustedDaysInMonth - startDate.getDate() / startDaysInMonth;
break;
case 'quarter':
difference =
Expand Down