Calculating friendly timedelta string

master
Davide Bongiovanni 6 years ago
parent 056de43a91
commit 0f6b449bf0

@ -38,11 +38,20 @@ def getUpcomingMeals():
meals = []
for row in r:
meals.append(dict(row))
seconds_to_deadline = (parse(meals[-1]['selection_deadline']) - datetime.datetime.now()).seconds
if seconds_to_deadline < 0:
meals[-1]['selection_deadline'] = 'Deadline passed'
else:
hours_td = round(seconds_to_deadline / 60 / 60)
days_td = hours_td / 24
hours_td = hours_td % 24
meals[-1]['selection_deadline'] = str(days_td) + ' days ' + str(hours_td)
r.close()
return meals
@app.route('/')
def index():
print (getUpcomingMeals())
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), current_user_name='Wille')
if __name__ == '__main__':

Loading…
Cancel
Save