commit 241552fb6db3d3cee3547d637994277a10f86425 Author: elpatron Date: Tue Jul 22 16:36:22 2025 +0200 Initialer Commit: Datumsrechner-App mit allen Funktionen, modernem Design und Template-Trennung diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8021d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd + +# Virtualenv +.venv/ +venv/ +ENV/ + +# VS Code +.vscode/ + +# Sonstige +.DS_Store +Thumbs.db + +# Logdateien +*.log + +# Test-/Coverage-Dateien +htmlcov/ +.coverage +.tox/ +.pytest_cache/ + +# Betriebssystem +*.swp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..074aca0 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Datumsberechnungen Web-App + +Diese kleine Python-Webanwendung ermöglicht folgende Datumsberechnungen: + +- Anzahl der Tage zwischen zwei Daten +- Anzahl der Werktage zwischen zwei Daten +- Anzeige des Wochentags eines Datums + +## Installation + +1. Python 3.8+ installieren +2. Abhängigkeiten installieren: + + ``` + pip install -r requirements.txt + ``` + +## Starten der App + +``` +python app.py +``` + +Die App ist dann unter http://localhost:5000 erreichbar. \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..49298fe --- /dev/null +++ b/app.py @@ -0,0 +1,105 @@ +from flask import Flask, render_template, request +from datetime import datetime, timedelta +import numpy as np + +app = Flask(__name__) + +# HTML-Template wird jetzt aus templates/index.html geladen + +WOCHENTAGE = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"] + +@app.route('/', methods=['GET', 'POST']) +def index(): + tage = werktage = wochentag = datumsrechnung = werktagsrechnung = kw_berechnen = kw_datum = None + active_idx = 0 + if request.method == 'POST': + action = request.form.get('action') + if action == 'tage': + active_idx = 0 + start = request.form.get('start1') + end = request.form.get('end1') + try: + d1 = datetime.strptime(start, '%Y-%m-%d') + d2 = datetime.strptime(end, '%Y-%m-%d') + 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') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + wochentag = WOCHENTAGE[d.weekday()] + except Exception: + wochentag = 'Ungültige Eingabe' + elif action == 'datumsrechnung': + active_idx = 3 + datum = request.form.get('datum4') + tage_input = request.form.get('tage4') + richtung = request.form.get('richtung4') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + tage_int = int(tage_input) + if richtung == 'add': + result = d + timedelta(days=tage_int) + else: + result = d - timedelta(days=tage_int) + datumsrechnung = result.strftime('%d.%m.%Y') + except Exception: + datumsrechnung = 'Ungültige Eingabe' + elif action == 'werktagsrechnung': + active_idx = 4 + datum = request.form.get('datum5') + tage_input = request.form.get('tage5') + richtung = request.form.get('richtung5') + try: + d = datetime.strptime(datum, '%Y-%m-%d').date() + tage_int = int(tage_input) + if richtung == 'add': + result = np.busday_offset(d, tage_int, roll='forward') + else: + result = np.busday_offset(d, -tage_int, roll='backward') + werktagsrechnung = np.datetime_as_string(result, unit='D') + # Formatierung auf deutsch + dt = datetime.strptime(werktagsrechnung, '%Y-%m-%d') + werktagsrechnung = dt.strftime('%d.%m.%Y') + except Exception: + werktagsrechnung = 'Ungültige Eingabe' + elif action == 'kw_berechnen': + active_idx = 5 + datum = request.form.get('datum6') + try: + d = datetime.strptime(datum, '%Y-%m-%d') + kw = d.isocalendar().week + kw_berechnen = f"KW {kw} ({d.year})" + except Exception: + kw_berechnen = 'Ungültige Eingabe' + elif action == 'kw_datum': + active_idx = 6 + jahr = request.form.get('jahr7') + kw = request.form.get('kw7') + try: + jahr = int(jahr) + kw = int(kw) + # Montag der KW + start = datetime.fromisocalendar(jahr, kw, 1) + end = datetime.fromisocalendar(jahr, kw, 7) + kw_datum = f"{start.strftime('%d.%m.%Y')} bis {end.strftime('%d.%m.%Y')}" + except Exception: + kw_datum = 'Ungültige Eingabe' + return render_template('index.html', tage=tage, werktage=werktage, wochentag=wochentag, datumsrechnung=datumsrechnung, werktagsrechnung=werktagsrechnung, kw_berechnen=kw_berechnen, kw_datum=kw_datum, active_idx=active_idx) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..9739ecd Binary files /dev/null and b/favicon.ico differ diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000..7845ed6 Binary files /dev/null and b/favicon.png differ diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 0000000..34ce014 --- /dev/null +++ b/favicon.svg @@ -0,0 +1,6 @@ + + + + + 15 + \ No newline at end of file diff --git a/idea.txt b/idea.txt new file mode 100644 index 0000000..27f5bb3 --- /dev/null +++ b/idea.txt @@ -0,0 +1,8 @@ +erstelle eine python web app, die verschiedene datumsberechnungen durchführt: +- Berechnung der Anzahl der Tage zwischen zwei Daten +- Berechnung der Anzahl der Werktage zwischen zwei Daten +- Anzeige des Wochentags eines Datums + +Beachte: +- Virtual Environment unter ./.venv +- Wir entwickeln unter Windows \ No newline at end of file diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..d961a14 --- /dev/null +++ b/logo.svg @@ -0,0 +1,8 @@ + + + + + 15 + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9ec642b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==3.0.3 +numpy==1.26.4 \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8529d9b --- /dev/null +++ b/templates/index.html @@ -0,0 +1,374 @@ + + + + + Elpatrons Datumsrechner + + + + + + +
+

Datumsberechnungen

+
+
+ +
+
+ + + +
+ {% if tage is not none %} +
Anzahl der Tage: {{ tage }}
+ {% endif %} +
+
+
+ +
+
+ + + +
+ {% if werktage is not none %} +
Anzahl der Werktage: {{ werktage }}
+ {% endif %} +
+
+
+ +
+
+ + +
+ {% if wochentag is not none %} +
Wochentag: {{ wochentag }}
+ {% endif %} +
+
+
+ +
+
+ + + + + + + +
+ {% if datumsrechnung is not none %} +
Ergebnis: {{ datumsrechnung }}
+ {% endif %} +
+
+
+ +
+
+ + + + + + + +
+ {% if werktagsrechnung is not none %} +
Ergebnis: {{ werktagsrechnung }}
+ {% endif %} +
+
+
+ +
+
+ + +
+ {% if kw_berechnen is not none %} +
Kalenderwoche: {{ kw_berechnen }}
+ {% endif %} +
+
+
+ +
+
+ + + +
+ {% if kw_datum is not none %} +
{{ kw_datum }}
+ {% endif %} +
+
+
+
+ + \ No newline at end of file