Add non-destructive dev seed on startup
This commit is contained in:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user