Skip to content

Commit 9e2b68c

Browse files
authored
fix: generate valid benchmark calendar dates (JhaSourav07#1718)
## Summary This PR fixes invalid date generation in the benchmark calendar dataset. ### Changes Made * Added a base `Date` object for benchmark generation * Replaced manual day-string construction with proper date arithmetic * Ensured generated dates roll over correctly across month boundaries ### Problem The previous implementation generated invalid dates such as: * 2026-05-32 * 2026-05-45 * 2026-05-98 because the day portion was incremented directly without considering calendar limits. ### Result Benchmark data now contains valid chronological dates across all generated weeks. Closes JhaSourav07#1677
2 parents 6a7b423 + dceae99 commit 9e2b68c

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

scripts/benchmark-svg.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ const baseParams = {
1717
scale: 'linear' as const,
1818
speed: sanitizeSpeed('8s'),
1919
};
20-
21-
const deterministicContributionCount = (weekIndex: number, dayIndex: number): number => {
22-
return ((weekIndex * 7 + dayIndex) * 13) % 20;
23-
};
20+
const startDate = new Date('2026-05-01');
2421

2522
const calendar = {
2623
totalContributions: 1240,
2724
weeks: Array.from({ length: 14 }, (_, weekIndex) => ({
2825
contributionDays: Array.from({ length: 7 }, (_, dayIndex) => ({
29-
contributionCount: deterministicContributionCount(weekIndex, dayIndex),
30-
date: `2026-05-${String(weekIndex * 7 + dayIndex + 1).padStart(2, '0')}`,
26+
contributionCount: Math.floor(Math.random() * 20),
27+
date: new Date(startDate.getTime() + (weekIndex * 7 + dayIndex) * 24 * 60 * 60 * 1000)
28+
.toISOString()
29+
.split('T')[0],
3130
})),
3231
})),
3332
};

0 commit comments

Comments
 (0)