mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 20:52:20 +01:00
14 lines
534 B
Python
14 lines
534 B
Python
from datetime import datetime, timedelta
|
|
|
|
|
|
def age_text(last_updated):
|
|
current_age = datetime.now() - last_updated
|
|
minutes = (current_age.seconds % 3600) / 60
|
|
hours = current_age.seconds / 3600
|
|
minutestr = "minute" if minutes == 1 else "minutes"
|
|
hourstr = "hour" if hours == 1 else "hours"
|
|
if current_age < timedelta(hours=1):
|
|
return "Stats were updated {:.0f} {} ago.".format(minutes, minutestr)
|
|
|
|
return "Stats were updated {:.0f} {} and {:.0f} {} ago.".format(hours, hourstr, minutes, minutestr)
|