Skip to content

Your favorite shift management application!

fix: adjust end date handling for all-day events in splitMultiDayEvent function

panteLx9653dcab92c1
diff --git a/.env.example b/.env.example
index 0585d67..c071ae3 100644
--- a/.env.example
+++ b/.env.example
@@ -16,6 +16,9 @@ GITHUB_API_REVALIDATE=3600 # GitHub API revalidation: 1 hour in seconds
# Internationalization (i18n)
DEFAULT_LOCALE=en # Default language if browser detection fails. Options: en, de
+# Timezone Setting
+TZ=Europe/Berlin # Set the application's timezone (e.g., Europe/Berlin)
+
# Application Settings (NOT supported on Docker deployments)
NODE_ENV=production
PORT=3000
diff --git a/lib/icloud-utils.ts b/lib/icloud-utils.ts
index 2034461..696356e 100644
--- a/lib/icloud-utils.ts
+++ b/lib/icloud-utils.ts
@@ -139,6 +139,15 @@ export function splitMultiDayEvent(
dayIndex: number;
}> = [];
+ // For all-day events, the end date in iCalendar format is exclusive
+ // (e.g., a one-day event on Dec 1 has end date Dec 2 00:00)
+ // We need to subtract one day for all-day events to get the actual last day
+ let adjustedEndDate = endDate;
+ if (isAllDay) {
+ adjustedEndDate = new Date(endDate);
+ adjustedEndDate.setDate(adjustedEndDate.getDate() - 1);
+ }
+
// Normalize dates to midnight for comparison
const startDay = new Date(
startDate.getFullYear(),
@@ -146,9 +155,9 @@ export function splitMultiDayEvent(
startDate.getDate()
);
const endDay = new Date(
- endDate.getFullYear(),
- endDate.getMonth(),
- endDate.getDate()
+ adjustedEndDate.getFullYear(),
+ adjustedEndDate.getMonth(),
+ adjustedEndDate.getDate()
);
// Check if event spans multiple days
@@ -166,8 +175,11 @@ export function splitMultiDayEvent(
const startMinutes = startDate.getMinutes().toString().padStart(2, "0");
startTime = `${startHours}:${startMinutes}`;
- const endHours = endDate.getHours().toString().padStart(2, "0");
- const endMinutes = endDate.getMinutes().toString().padStart(2, "0");
+ const endHours = adjustedEndDate.getHours().toString().padStart(2, "0");
+ const endMinutes = adjustedEndDate
+ .getMinutes()
+ .toString()
+ .padStart(2, "0");
endTime = `${endHours}:${endMinutes}`;
}
@@ -199,8 +211,14 @@ export function splitMultiDayEvent(
} else if (i === daysDiff) {
// Last day: start at midnight, use actual end time
startTime = "00:00";
- const endHours = endDate.getHours().toString().padStart(2, "0");
- const endMinutes = endDate.getMinutes().toString().padStart(2, "0");
+ const endHours = adjustedEndDate
+ .getHours()
+ .toString()
+ .padStart(2, "0");
+ const endMinutes = adjustedEndDate
+ .getMinutes()
+ .toString()
+ .padStart(2, "0");
endTime = `${endHours}:${endMinutes}`;
}
// Middle days keep default 00:00 - 23:59