Fix DST handling in computeHeuristics by restoring UTC normalization

Co-authored-by: THoguet <61246905+THoguet@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andTHoguet committed 2025-11-03 17:15:33 +00:00
1 parent 125786e2d9
commit ace0d70a6e
1 file changed
+16 -5
+16 -5
View File
@@ -478,16 +478,27 @@ export class SelectedDates implements SelectedDateInterface {
return aStart - bStart; return aStart - bStart;
}); });
const oneDayInMs = 24 * 60 * 60 * 1000;
// PRIMARY: Optimize adjacency - reduce "little holes" between vacation periods // PRIMARY: Optimize adjacency - reduce "little holes" between vacation periods
for (let i = 0; i < sorted.length - 1; i++) { for (let i = 0; i < sorted.length - 1; i++) {
const current = sorted[i]; const current = sorted[i];
const next = sorted[i + 1]; const next = sorted[i + 1];
// Use timestamps directly - dates should already be normalized // Get dates as UTC strings to remove timezone issues (handles DST properly)
const currentEndTime = current.range.end?.getTime() ?? 0; const currentEndDate = new Date(current.range.end ?? new Date());
const nextStartTime = next.range.start?.getTime() ?? 0; const nextStartDate = new Date(next.range.start ?? new Date());
// Convert to date-only strings (YYYY-MM-DD) to compare calendar days
const currentEndString = currentEndDate.toISOString().split('T')[0];
const nextStartString = nextStartDate.toISOString().split('T')[0];
// Parse back to dates at UTC midnight
const currentEndDateNormalized = new Date(currentEndString + 'T00:00:00Z');
const nextStartDateNormalized = new Date(nextStartString + 'T00:00:00Z');
const currentEndTime = currentEndDateNormalized.getTime();
const nextStartTime = nextStartDateNormalized.getTime();
const oneDayInMs = 24 * 60 * 60 * 1000;
// Check if adjacent (next day) - this is the best case! // Check if adjacent (next day) - this is the best case!
if (nextStartTime - currentEndTime === oneDayInMs) { if (nextStartTime - currentEndTime === oneDayInMs) {