Reputation: 473873
I've recently stumbled upon this awesome pendulum
"datetimes made easy" library.
It has a very nice feature of displaying "human like" diffs between datetimes:
In [1]: import pendulum
In [2]: now = pendulum.now()
In [3]: future = now.add(years=10)
In [4]: future.diff_for_humans()
Out[4]: '10 years from now'
But, is it possible to make it work for a more complicated difference - say "years" and "weeks"?
In [5]: future = now.add(years=10, weeks=5)
In [6]: future.diff_for_humans()
Out[6]: '10 years from now'
I would expect it to output 10 years and 5 weeks from now
.
Upvotes: 1
Views: 3345
Reputation: 2891
From the Pendulum module readme:
now = pendulum.now()
future = now.add(years=10, weeks=5)
delta = future - now
delta.in_words()
>>>'10 years 1 month 4 days'
https://github.com/sdispater/pendulum
Upvotes: 3