Mist, jetzt vielleicht

This commit is contained in:
rxf
2026-03-11 20:33:19 +01:00
parent bc235e4e32
commit a949ebcdc8
28 changed files with 1666 additions and 74 deletions

26
lib/checkAblauf.ts Normal file
View File

@@ -0,0 +1,26 @@
import moment from 'moment';
import { TabletteRaw } from '@/types/tablette';
const VORLAUF = parseInt(process.env.VORLAUF || '14', 10);
export interface AblaufResult {
akt: number;
until: Date;
rtage: number;
warn: boolean;
}
export function checkAblauf(item: Pick<TabletteRaw, 'cnt' | 'pday' | 'at'>): AblaufResult {
const now = moment();
const atday = moment(item.at);
const days = moment.duration(now.diff(atday)).asDays();
const aktAnzahl = item.cnt - Math.floor(days) * item.pday;
const reichtTage = Math.floor(aktAnzahl / item.pday);
const rbis = now.add(reichtTage, 'day').startOf('day');
return {
akt: aktAnzahl,
until: rbis.toDate(),
rtage: reichtTage,
warn: reichtTage <= VORLAUF,
};
}