This version brings small changes and performance improvements.

New features

New keep_time keyword for next()/previous()

The next() and previous() methods now support a keep_time keyword argument to maintain the time information.

>>> import pendulum

>>> dt = pendulum.now()
>>> dt.to_datetime_string()
'2017-02-17 15:22:54'
>>> dt.next(pendulum.FRIDAY).to_datetime_string()
'2017-02-24 00:00:00'
>>> dt.next(pendulum.FRIDAY, keep_time=True).to_datetime_string()
'2017-02-24 15:22:54'

Changes

  • Improved diff_for_humans() method to display more intuitive strings on edge cases.

    >>> import pendulum
    
    # Before
    >>> pendulum.now().add(years=1).diff_for_humans()
    '11 months from now'
    
    # Now
    >>> pendulum.now().add(years=1).diff_for_humans()
    '1 year from now'
    
  • Formatting (with f-strings or format()) will now use the configured formatter.

    >>> import pendulum
    
    >>> dt = pendulum.create(2017, 2, 20, 12, 34, 56)
    >>> '{:%Y-%m-%d %H:%M:%S}'.format(dt)
    '2017-02-20 12:34:56'
    >>> f'{dt:%Y-%m-%d %H:%M:%S}'
    '2017-02-20 12:34:56'
    
    >>> pendulum.set_formatter('alternative')
    >>> '{:YYYY-MM-DD HH:mm:ss}'.format(dt)
    '2017-02-20 12:34:56'
    >>> f'{dt:YYYY-MM-DD HH:mm:ss}'
    '2017-02-20 12:34:56'
    
  • Greatly improved diff() performance.