Fix of some timezone problems
Release Inventarsystem / release-docker (push) Successful in 3m18s

This commit is contained in:
2026-09-15 10:51:00 +02:00
parent 6311e7710a
commit a8f3907f34
2 changed files with 24 additions and 13 deletions
+5 -5
View File
@@ -42,12 +42,12 @@ def _get_client():
return MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
# Add this helper function after imports
def ensure_timezone_aware(dt):
"""Ensures a datetime is timezone-aware, using UTC if naive"""
"""Return a timezone-aware datetime, treating naive DB values as UTC."""
if dt is None:
return None
if dt.tzinfo is None:
# Treat naive datetimes as UTC
return dt.replace(tzinfo=None)
# PyMongo returns BSON datetimes as naive UTC unless tz_aware is enabled.
return dt.replace(tzinfo=datetime.timezone.utc)
return dt
def get_current_status(ausleihung, log_changes=False, user=None):
@@ -82,8 +82,8 @@ def get_current_status(ausleihung, log_changes=False, user=None):
return 'completed'
current_time = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
start_time = ausleihung.get('Start')
end_time = ausleihung.get('End')
start_time = ensure_timezone_aware(ausleihung.get('Start'))
end_time = ensure_timezone_aware(ausleihung.get('End'))
# Wenn kein Startdatum vorhanden ist, Status auf 'planned' setzen
if not start_time: