Pendulum 0.8.0 is now out.

It is mostly a deprecation notification release before the first stable release and it also improves the parsing of ISO 8601 strings.

For the full list of changes, see the Change Log

New Features

New on() and at() methods

These methods replace the with_date() and with_time() methods which are now deprecated.

>>> import pendulum >>> from datetime import time , date >>> dt = pendulum . now () >>> dt . on ( 1975 , 5 , 21 ) . at ( 22 , 32 , 5 ) . to_datetime_string () '1975-05-21 22:32:05'

New strict keyword argument for parse()

A new strict keyword argument has been added to parse() in order to get the exact type matching the parsed string.

>>> import pendulum >>> pendulum . parse ( '2012-05-03' , strict = True ) # <Date [2012-05-03]> >>> pendulum . parse ( '12:04:23' , strict = True ) # <Time [12:04:23]>

Ability to pass the length of the range() method

It is now possible to give the length of the gap for the range() method on the Period class.

>>> import pendulum >>> start = pendulum . Pendulum ( 2000 , 1 , 1 ) >>> end = pendulum . Pendulum ( 2000 , 1 , 10 ) >>> period = pendulum . period ( start , end ) >>> for dt in period . range ( 'days' , 2 ): >>> print ( dt ) '2000-01-01T00:00:00+00:00' '2000-01-03T00:00:00+00:00' '2000-01-05T00:00:00+00:00' '2000-01-07T00:00:00+00:00' '2000-01-09T00:00:00+00:00'

You can now get a normalized datetime object directly from a Timezone by using the datetime() method:

>>> import pendulum >>> tz = pendulum . timezone ( 'Europe/Paris' ) >>> dt = tz . datetime ( 2013 , 3 , 31 , 2 , 30 ) >>> dt . isoformat () '2013-03-31T03:30:00+02:00'

Changes

Improved parsing of ISO 8601 strings.

The library now supports parsing most of the ISO 8601 strings:

String Output 20161001T143028+0530 2016-10-01T14:30:28+05:30 20161001T14 2016-10-01T14:00:00+00:00

String Output 2012 2012-01-01T00:00:00+00:00 2012-05-03 2012-05-03T00:00:00+00:00 20120503 2012-05-03T00:00:00+00:00 2012-05 2012-05-01T00:00:00+00:000

Ordinal day

String Output 2012-007 2012-01-07T00:00:00+00:00 2012007 2012-01-07T00:00:00+00:00

Week number

String Output 2012-W05 2012-01-30T00:00:00+00:00 2012W05 2012-01-30T00:00:00+00:00 2012-W05-5 2012-02-03T00:00:00+00:00 2012W055 2012-02-03T00:00:00+00:00

Time

When passing only time information the date will default to today.

String Output 00:00 2016-12-17T00:00:00+00:00 12:04:23 2016-12-17T12:04:23+00:00 120423 2016-12-17T12:04:23+00:00 12:04:23.45 2016-12-17T12:04:23.450000+00:00

You can pass the strict keyword argument to parse() to get the exact type that the string represents:

Deprecations