jaraco/inflect

time difference inflected as before/after

Open

#41 opened on Mar 30, 2017

 (1 comment) (0 reactions) (0 assignees)Python (125 forks)github user discovery
featurehelp wanted

Repository metrics

Stars
 (1,082 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

I'd like to see a feature like the following:

>>> p.date_diff(datetime.timedelta(minutes=-30))
'00:30:00 before'
>>> p.date_diff(5)
'00:00:05 after'
>>> p.date_diff(0)
'at'

I would expect one to use the result to produce nice output for a time difference like:

Your flight departed 00:00:05 after its scheduled departure.

It would be nice if it accepted a time formatter such that it could alternately emit:

>>> p.date_diff(datetime.timedelta(minutes=-30), fmt=nice_time)
'30 minutes before'
>>> p.date_diff(5, fmt=nice_time)
'five seconds after'
>>> p.date_diff(0, fmt=nice_time)
'at'

Perhaps that inflection is too trivial for a library like inflect. Or perhaps there are nuances I haven't yet considered.

Contributor guide