1

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.

0

1 Answer 1

3

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

6
  • Good finding, I wonder why there is this difference between the diff_for_humans() and in_words(). Thanks!
    – alecxe
    Commented Dec 15, 2017 at 16:18
  • 1
    You could always look in the implementation for that. I linked the module sources.
    – BoboDarph
    Commented Dec 15, 2017 at 16:19
  • 1
    Okay, read the source, Luke :)
    – alecxe
    Commented Dec 15, 2017 at 16:22
  • It doesn't answer the question if the 'from now' is desired. Just adding that manually isn't an option when localization is required. Commented Dec 15, 2017 at 16:23
  • 1
    I just opened an issue for this: github.com/sdispater/pendulum/issues/169. Commented Dec 15, 2017 at 16:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.