Fix: Werktagsberechnung robust, Checkbox-Auswertung verbessert, Tests angepasst

This commit is contained in:
2025-07-24 15:31:55 +02:00
parent b71bca3bb4
commit 0674849b6c
3 changed files with 44 additions and 51 deletions

22
app.py
View File

@@ -47,28 +47,22 @@ def index():
with open(log_path, 'a', encoding='utf-8') as f:
from datetime import datetime as dt
f.write(f"{dt.now().isoformat()} FUNC: {action}\n")
if action == 'tage':
if action == 'tage_werktage':
active_idx = 0
start = request.form.get('start1')
end = request.form.get('end1')
is_werktage = request.form.get('werktage') in ('on', 'true', '1', True)
try:
d1 = datetime.strptime(start, '%Y-%m-%d')
d2 = datetime.strptime(end, '%Y-%m-%d')
tage = abs((d2 - d1).days)
if is_werktage:
if d1 > d2:
d1, d2 = d2, d1
tage = np.busday_count(d1.date(), (d2 + timedelta(days=1)).date())
else:
tage = abs((d2 - d1).days)
except Exception:
tage = 'Ungültige Eingabe'
elif action == 'werktage':
active_idx = 1
start = request.form.get('start2')
end = request.form.get('end2')
try:
d1 = datetime.strptime(start, '%Y-%m-%d')
d2 = datetime.strptime(end, '%Y-%m-%d')
if d1 > d2:
d1, d2 = d2, d1
werktage = np.busday_count(d1.date(), (d2 + timedelta(days=1)).date())
except Exception:
werktage = 'Ungültige Eingabe'
elif action == 'wochentag':
active_idx = 2
datum = request.form.get('datum3')