diff --git a/backend/placeholder_resolver.py b/backend/placeholder_resolver.py index 928fd0e..efb8835 100644 --- a/backend/placeholder_resolver.py +++ b/backend/placeholder_resolver.py @@ -225,16 +225,21 @@ def get_activity_summary(profile_id: str, days: int = 14) -> str: return f"{row['count']} Einheiten in {days} Tagen (Ø {avg_min} min/Einheit, {int(row['total_kcal'] or 0)} kcal gesamt)" -def calculate_age(dob: Optional[str]) -> str: - """Calculate age from date of birth.""" +def calculate_age(dob) -> str: + """Calculate age from date of birth (accepts date object or string).""" if not dob: return "unbekannt" try: - birth = datetime.strptime(dob, '%Y-%m-%d') - today = datetime.now() + # Handle both datetime.date objects and strings + if isinstance(dob, str): + birth = datetime.strptime(dob, '%Y-%m-%d').date() + else: + birth = dob # Already a date object from PostgreSQL + + today = datetime.now().date() age = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day)) return str(age) - except: + except Exception as e: return "unbekannt"