Improve format of workout start date on overview page
This commit is contained in:
7
app.py
7
app.py
@@ -204,13 +204,18 @@ def get_workouts_for_user(user_id):
|
||||
workouts_data.append({
|
||||
'id': workout.id,
|
||||
'user_id': user_id,
|
||||
'start_time': start_time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'start_time': format_date_with_ordinal(start_time, '%H:%M %B %dth %Y'),
|
||||
'duration': format_duration(duration),
|
||||
'average_rpm': int(average_rpm)
|
||||
})
|
||||
return workouts_data
|
||||
|
||||
|
||||
def format_date_with_ordinal(d, format_string):
|
||||
ordinal = {'1': 'st', '2': 'nd', '3': 'rd'}.get(str(d.day)[-1:], 'th')
|
||||
return d.strftime(format_string).replace('{th}', ordinal)
|
||||
|
||||
|
||||
def format_duration(duration):
|
||||
hours, remainder = divmod(duration.seconds, 3600)
|
||||
minutes, _ = divmod(remainder, 60)
|
||||
|
||||
Reference in New Issue
Block a user