diff --git a/src/app/dashboard/notdienst/plan/actions.ts b/src/app/dashboard/notdienst/plan/actions.ts
index 294f48d..e4425c8 100644
--- a/src/app/dashboard/notdienst/plan/actions.ts
+++ b/src/app/dashboard/notdienst/plan/actions.ts
@@ -33,8 +33,8 @@ export async function generatePlanAction() {
where: {
kitaId,
date: {
- gte: new Date(targetYear, targetMonth - 1, 1),
- lt: new Date(targetYear, targetMonth, 1),
+ gte: new Date(Date.UTC(targetYear, targetMonth - 1, 1)),
+ lt: new Date(Date.UTC(targetYear, targetMonth, 1)),
},
},
include: { child: { select: { familyId: true } } },
@@ -141,7 +141,8 @@ export async function updateAssignmentAction(
const session = await requireRole([UserRole.ADMIN, UserRole.KOORDINATOR]);
const kitaId = session.user.kitaId!;
- const parsedDate = new Date(date);
+ const [yr, mo, dy] = date.slice(0, 10).split("-").map(Number);
+ const parsedDate = new Date(Date.UTC(yr, mo - 1, dy));
try {
await prisma.$transaction(async (tx) => {
diff --git a/src/app/dashboard/notdienst/plan/plan-view.tsx b/src/app/dashboard/notdienst/plan/plan-view.tsx
index 1d17495..4aa5747 100644
--- a/src/app/dashboard/notdienst/plan/plan-view.tsx
+++ b/src/app/dashboard/notdienst/plan/plan-view.tsx
@@ -121,7 +121,8 @@ export function PlanView({ planId, status, days, allChildren }: PlanViewProps) {
{days.map((day) => {
- const dateObj = new Date(day.date);
+ const [yr, mo, dy] = day.date.slice(0, 10).split("-").map(Number);
+ const dateObj = new Date(yr, mo - 1, dy);
const isUnbesetzt = !day.childId;
return (
diff --git a/src/lib/date-utils.ts b/src/lib/date-utils.ts
index f5b1c49..bb6e209 100644
--- a/src/lib/date-utils.ts
+++ b/src/lib/date-utils.ts
@@ -1,13 +1,8 @@
import {
addMonths,
- endOfMonth,
getDate,
getYear,
getMonth,
- isWeekend,
- eachDayOfInterval,
- startOfMonth,
- startOfDay,
format,
} from "date-fns";
import { de } from "date-fns/locale";
@@ -36,13 +31,28 @@ export function getTargetMonthData(now = new Date()) {
}
export function getWorkingDaysOfMonth(year: number, month: number) {
- // month ist 1-12, Date erwartet 0-11
- const start = startOfMonth(new Date(year, month - 1));
- const end = endOfMonth(start);
+ const start = new Date(Date.UTC(year, month - 1, 1));
+ const end = new Date(Date.UTC(year, month, 0)); // last day of month
- const days = eachDayOfInterval({ start, end });
-
- return days
- .filter((day) => !isWeekend(day))
- .map((day) => startOfDay(day));
+ const days: Date[] = [];
+ const current = new Date(start);
+ while (current <= end) {
+ const dayOfWeek = current.getUTCDay(); // 0 is Sunday, 6 is Saturday
+ if (dayOfWeek !== 0 && dayOfWeek !== 6) {
+ days.push(new Date(current));
+ }
+ current.setUTCDate(current.getUTCDate() + 1);
+ }
+ return days;
+}
+
+export function formatDateKey(date: Date) {
+ return format(date, "yyyy-MM-dd");
+}
+
+export function formatUtcDateKey(date: Date) {
+ const yyyy = date.getUTCFullYear();
+ const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
+ const dd = String(date.getUTCDate()).padStart(2, "0");
+ return `${yyyy}-${mm}-${dd}`;
}