Add non-destructive dev seed on startup

This commit is contained in:
t.indorf
2026-05-06 22:31:07 +02:00
parent 9f452fccac
commit b686e714ff
77 changed files with 10862 additions and 87 deletions
+48
View File
@@ -0,0 +1,48 @@
import {
addMonths,
endOfMonth,
getDate,
getYear,
getMonth,
isWeekend,
eachDayOfInterval,
startOfMonth,
startOfDay,
format,
} from "date-fns";
import { de } from "date-fns/locale";
/**
* Der Notdienst-Plan wird immer für den nächsten Monat erstellt.
* Nach dem 26. des aktuellen Monats ist der Plan gesperrt.
*/
const LOCK_DAY = 26;
export function getTargetMonthData(now = new Date()) {
const currentDay = getDate(now);
const nextMonthDate = addMonths(now, 1);
const targetYear = getYear(nextMonthDate);
const targetMonth = getMonth(nextMonthDate) + 1; // 1-12
// Sperre aktiv, sobald der aktuelle Tag (im aktuellen Monat) > LOCK_DAY ist.
const isLocked = currentDay > LOCK_DAY;
return {
targetYear,
targetMonth,
isLocked,
monthName: format(nextMonthDate, "MMMM yyyy", { locale: de }),
};
}
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 days = eachDayOfInterval({ start, end });
return days
.filter((day) => !isWeekend(day))
.map((day) => startOfDay(day));
}