Datetime Helpers

Dooku provides some missed primitives for datetime manipulating. This part was born during Holocron development where we were needed to do next things:

  • represent a datetime in ISO-8601 format;
  • convert a datetime from local time to UTC and vice versa.

Timezones

dooku.datetime.UTC

Implements a UTC datetime.tzinfo.

You can use it to attach timezone information to datetime instances. Such information becomes useful if you want to represent a datetime instance in various timezone notations.

Example:

>>> from dooku.datetime import UTC
>>> dt = datetime.datetime.now(UTC)
>>> dt
datetime.datetime(2014, 5, 29, 20, 22, 17, 426248, tzinfo=<...>)
dooku.datetime.Local

Implements a Local datetime.tzinfo.

You can use it to attach timezone information to datetime instances. Such information becomes useful if you want to represent a datetime instance in various timezone notations.

Example:

>>> from dooku.datetime import UTC, Local
>>> dt = datetime.datetime.now(UTC)
>>> dt
datetime.datetime(2014, 5, 29, 20, 22, 17, 426248, tzinfo=<...>)
>>>
>>> dt = dt.astimezone(Local)
>>> dt
datetime.datetime(2014, 5, 29, 23, 22, 17, 426248, tzinfo=<...>)

Formatters

dooku.datetime.to_iso8601(dt, tz=None)

Returns an ISO-8601 representation of a given datetime instance.

>>> to_iso8601(datetime.datetime.now())
'2014-10-01T23:21:33.718508Z'
Parameters:
  • dt – a datetime instance
  • tz – a tzinfo to use; if None - use a default one
dooku.datetime.to_rfc3339(dt, tz=None)

The RFC-3339 is a profile (subset) of more complex ISO-8601. So it’s just an alias for to_iso8601() function.