-
-
Notifications
You must be signed in to change notification settings - Fork 163
Support remaining time in format_timedelta #246
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_timedelta
It 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_timedelta
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.