-
-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Description
Babel supports positive and negative timedeltas. From their code (babel/dates.py):
>>> format_timedelta(timedelta(hours=1), add_direction=True, locale='en')
'in 1 hour'
>>> format_timedelta(timedelta(hours=-1), add_direction=True, locale='en')
'1 hour ago'Flask-Babel, however, only supports elapsed time. It subtracts the timedelta value from the current time:
if isinstance(datetime_or_timedelta, datetime):
datetime_or_timedelta = datetime.utcnow() - datetime_or_timedeltaIt would be great to properly handle dates in the future as well.
How about something like this?
if isinstance(datetime_or_timedelta, datetime):
now = datetime.utcnow()
if datetime_or_timedelta > now:
datetime_or_timedelta = datetime_or_timedelta - now
else:
datetime_or_timedelta = now - datetime_or_timedeltaMetadata
Metadata
Assignees
Labels
No labels