def strfage(time, fmt=None):
""" Format time/age
"""
if not hasattr(time, "days"): # dirty hack
now = datetime.now()
if isinstance(time, str):
time = datetime.strptime(time, '%Y-%m-%dT%H:%M:%S')
time = (now - time)
d = {"days": time.days}
d["hours"], rem = divmod(time.seconds, 3600)
d["minutes"], d["seconds"] = divmod(rem, 60)
s = "{seconds} seconds"
if d["minutes"]:
s = "{minutes} minutes " + s
if d["hours"]:
s = "{hours} hours " + s
if d["days"]:
s = "{days} days " + s
return s.format(**d)
评论列表
文章目录