diff --git a/app.py b/app.py index b788213..af5af14 100644 --- a/app.py +++ b/app.py @@ -164,10 +164,10 @@ def workouts(user_id): db.session.add(heart_rate_reading) if cadence_readings: - start_time = min( - c['timestamp'] for c in cadence_readings) - end_time = max( - c['timestamp'] for c in cadence_readings) + timestamps = [datetime_converter( + c['timestamp']) for c in cadence_readings] + start_time = min(timestamps) + end_time = max(timestamps) duration = end_time - start_time duration = duration.total_seconds() average_rpm = sum( @@ -437,6 +437,10 @@ def format_duration(duration): return f"{minutes}m" +def datetime_converter(datetime_str: str) -> datetime: + return datetime.strptime(datetime_str, "%Y-%m-%dT%H:%M:%S%z") + + if __name__ == '__main__': # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000))