Files
Betriebsf-hrungssoftware/src/domain/zeit.ts
Claude 334cd9357e
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled
Pausenabzug standardmäßig voll: 6:10 wird 5:40 (0.15.1)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
2026-10-20 21:26:46 +00:00

63 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Arbeitszeit und Pausenabzug (M3, Henning 18.10.2026). Rechnet in Minuten.
// Abzug nach der Summe des Tages: bis 6 Std keiner, über 6 bis 9 Std 30 Min, über 9 bis 10 Std 45 Min, über 10 Std 1 Std.
// Von Hand eingetragene Pausen zählen mit; längere Pausen als 1 Std trägt man von Hand ein.
// Nur für Angestellte, nicht für den Inhaber.
/** bis_grenze: knapp über einer Grenze wird nur bis zur Grenze abgezogen (6:10 → 6:00); voll: immer der ganze Abzug */
export type Abzugsart = "bis_grenze" | "voll";
const STUFEN: [number, number][] = [[360, 0], [540, 30], [600, 45], [Infinity, 60]];
/** Pause nach der Regel für eine Anwesenheit (Ende minus Beginn) */
export function regelPause(anwesend: number): number {
for (const [bis, pause] of STUFEN) if (anwesend <= bis) return pause;
return 60;
}
export interface Tagesrechnung {
/** Ende minus Beginn */
anwesend: number;
/** von Hand eingetragen */
handPause: number;
/** zusätzlich automatisch abgezogen */
abzug: number;
/** bezahlte Arbeitszeit */
netto: number;
/** über 10 Std. Arbeitszeit (Grenze nach Arbeitszeitgesetz) */
ueberZehn: boolean;
}
export function rechneTag(anwesend: number, handPause: number, angestellt: boolean, art: Abzugsart = "voll"): Tagesrechnung {
if (!(anwesend >= 0) || !(handPause >= 0)) throw new Error("Zeiten ungültig");
const hand = Math.min(handPause, anwesend);
let pflicht = 0;
if (angestellt) {
pflicht = regelPause(anwesend);
if (art === "bis_grenze") {
// länger da sein ergibt nie weniger Stunden: höchstens bis zur zuletzt überschrittenen Grenze abziehen
let netto = anwesend - pflicht;
for (const [grenze] of STUFEN) if (grenze < anwesend) netto = Math.max(netto, grenze - regelPause(grenze));
pflicht = anwesend - netto;
}
}
const pause = Math.max(hand, pflicht);
const netto = anwesend - pause;
return { anwesend, handPause: hand, abzug: pause - hand, netto, ueberZehn: netto > 600 };
}
/** "07:30" → 450 */
export function minuten(uhrzeit: string): number {
const m = /^(\d{1,2}):(\d{2})(?::\d{2})?$/.exec(uhrzeit.trim());
if (!m || Number(m[1]) > 24 || Number(m[2]) > 59) throw new Error(`Uhrzeit ungültig: ${uhrzeit}`);
return Number(m[1]) * 60 + Number(m[2]);
}
/** 450 → "07:30" */
export const uhrzeit = (min: number) => `${String(Math.floor(min / 60)).padStart(2, "0")}:${String(Math.round(min % 60)).padStart(2, "0")}`;
/** 510 → "8:30" (Stunden:Minuten) */
export const dauerText = (min: number) => `${min < 0 ? "−" : ""}${Math.floor(Math.abs(min) / 60)}:${String(Math.round(Math.abs(min) % 60)).padStart(2, "0")}`;
/** 510 → 8.5 (Stunden mit zwei Stellen) */
export const stunden = (min: number) => Math.round((min / 60) * 100) / 100;