Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: time unit computeCountToTimeScale month exactitude #4909\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
10 changes: 7 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,7 @@ export function computeCountToTimeScale(

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

switch (timeScale) {
case 'second':
difference = (adjusted_date.getTime() - startDate.getTime()) / msInSecond;
Expand All @@ -694,12 +695,15 @@ export function computeCountToTimeScale(
difference = (adjusted_date.getTime() - startDate.getTime()) / msInWeek;
break;
case 'month':
const startDaysInMonth = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0).getDate();
const adjustedDaysInMonth = new Date(adjusted_date.getFullYear(), adjusted_date.getMonth() + 1, 0).getDate();
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
Loading