From ace0d70a6e1f48bbe2e94ccd919fd30639e7d65f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 3 Nov 2025 17:15:33 +0000 Subject: [PATCH] Fix DST handling in computeHeuristics by restoring UTC normalization Co-authored-by: THoguet <61246905+THoguet@users.noreply.github.com> --- src/app/services/calendar-service.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/services/calendar-service.ts b/src/app/services/calendar-service.ts index ecbe90a..a910fb5 100644 --- a/src/app/services/calendar-service.ts +++ b/src/app/services/calendar-service.ts @@ -478,16 +478,27 @@ export class SelectedDates implements SelectedDateInterface { return aStart - bStart; }); - const oneDayInMs = 24 * 60 * 60 * 1000; - // PRIMARY: Optimize adjacency - reduce "little holes" between vacation periods for (let i = 0; i < sorted.length - 1; i++) { const current = sorted[i]; const next = sorted[i + 1]; - // Use timestamps directly - dates should already be normalized - const currentEndTime = current.range.end?.getTime() ?? 0; - const nextStartTime = next.range.start?.getTime() ?? 0; + // Get dates as UTC strings to remove timezone issues (handles DST properly) + const currentEndDate = new Date(current.range.end ?? new Date()); + 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! if (nextStartTime - currentEndTime === oneDayInMs) {