From a480c56a54e33c9a5e6b4374c5c0485198471b60 Mon Sep 17 00:00:00 2001 From: cottongin Date: Mon, 2 Nov 2026 19:39:53 -0500 Subject: [PATCH] fix: timezone conversion dayOffset month-boundary bug and overnight endDayIdx calculation Co-authored-by: Cursor --- src/render/week-grid.ts | 13 ++++--------- src/time/zones.ts | 8 +++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/render/week-grid.ts b/src/render/week-grid.ts index 6c985a0..9a45cb0 100644 --- a/src/render/week-grid.ts +++ b/src/render/week-grid.ts @@ -140,15 +140,10 @@ function computeShowPlacement( let startMin = convertedStart.hour * 60 + convertedStart.minute; let endMin = convertedEnd.hour * 60 + convertedEnd.minute; - const endDayIdx = (sourceDayIdx + convertedEnd.dayOffset + 7) % 7; - if (isOvernightSource || endDayIdx !== displayDayIdx || endMin <= startMin) { - if (endDayIdx === displayDayIdx && endMin <= startMin) { - endMin += 24 * 60; - } else if (endDayIdx !== displayDayIdx) { - endMin += 24 * 60; - } else if (isOvernightSource) { - endMin += 24 * 60; - } + const endBaseDayIdx = isOvernightSource ? sourceDayIdx + 1 : sourceDayIdx; + const endDayIdx = (endBaseDayIdx + convertedEnd.dayOffset + 7) % 7; + if (endDayIdx !== displayDayIdx || endMin <= startMin) { + endMin += 24 * 60; } const startDisplay = formatTime12(convertedStart.hour, convertedStart.minute); diff --git a/src/time/zones.ts b/src/time/zones.ts index a144542..5d44025 100644 --- a/src/time/zones.ts +++ b/src/time/zones.ts @@ -60,11 +60,17 @@ export function convertTime( const toHour = parseInt(toParts.find((p) => p.type === "hour")!.value); const toMin = parseInt(toParts.find((p) => p.type === "minute")!.value); const toDay = parseInt(toParts.find((p) => p.type === "day")!.value); + const toMonth = parseInt(toParts.find((p) => p.type === "month")!.value); + const toYear = parseInt(toParts.find((p) => p.type === "year")!.value); const fromCorrectedParts = fromFormatter.formatToParts(correctedUtc); const fromDay = parseInt(fromCorrectedParts.find((p) => p.type === "day")!.value); + const fromMonth = parseInt(fromCorrectedParts.find((p) => p.type === "month")!.value); + const fromYear = parseInt(fromCorrectedParts.find((p) => p.type === "year")!.value); - const dayOffset = toDay - fromDay; + const fromDate = Date.UTC(fromYear, fromMonth - 1, fromDay); + const toDate = Date.UTC(toYear, toMonth - 1, toDay); + const dayOffset = Math.round((toDate - fromDate) / (24 * 60 * 60 * 1000)); return { hour: toHour === 24 ? 0 : toHour, minute: toMin, dayOffset }; }