Learn Python with Talk Python's Python courses

Unlock the mysteries of time, Python's datetime that is!

Episode #271, published Sat, Jul 4, 2020, recorded Thu, Jun 18, 2020.

This episode is carbon neutral.
Time is a simple thing, right? And working with it in Python is great. You just import datetime and then (somewhat oddly) use the datetime class from that module.

Oh except, there are times with timezones, and times without. And why is there a total_seconds() but not total_minutes(), hours() or days() on timedelta? How about computing the number of weeks?

What if you wanted to iterate over the next 22 workdays, skipping weekends?

Ok, we'd better talk about time in Python! Good thing Paul Ganssle is here. He's a core developer who controls time in CPython.

Links from the show

Talk Python Training Humble Bundle: humblebundle.com

Paul on Twitter: @pganssle
Paul's Blog: blog.ganssle.io
Paul's Website: ganssle.io

Datetime blog posts
pytz: The fastest footgun in the West: blog.ganssle.io
Stop using utcnow and utcfromtimestamp: blog.ganssle.io
A curious case of non-transitive datetime comparison: blog.ganssle.io
Semantics of timezone-aware datetime arithmetic: blog.ganssle.io


PEP 495: Local time disambiguation: python.org
PEP 615: Support for the IANA Time Zone Database in the Standard Library: python.org

zoneinfo documentation in Python 3.9: docs.python.org
backports.zoneinfo: pypi.org
pytz_deprecation_shim: readthedocs.io

Extra libraries
dateutil: readthedocs.io
break-my-python: pypi.org
arrow: readthedocs.io
pendulum: pendulum.eustace.io

Indiana Time Zones: google.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe on YouTube: youtube.com
Follow Talk Python on Twitter: @talkpython
Follow Michael on Twitter: @mkennedy

Want to go deeper? Check out our courses

Paul Ganssle
Paul Ganssle
Paul is the maintainer of the dateutil package and also a maintainer of the setuptools project.
Episode sponsored by
Ads served ethically
Become a friend of the show
Stay in the know and get a chance to win our contests.
See our privacy statement about email communications.