Hacker News new | ask | show | jobs
by bhargav 1138 days ago
> The title of this post claims that pytz is the fastest footgun in the west, by which I mean that pytz is a quite well-optimized library, and historically it has been faster than dateutil.tz

Wat. The author has no idea what a foot gun is.

Pytz is a must because using the standard library and timezone manipulations often leads to bugs. There are nuances around “naive” date times where one can easily just add a fake timezone value, not realizing that the time didn’t actually get localized to the timezone.

There are other libraries such as Arrow and Pendulum worth checking out but pytz is probably enough.

3 comments

Eh? They're pointing out it's an extremely well optimised and fast library, and then pointing out a number of ways in which it's a footgun because it doesn't behave as you'd expect, e.g.

    NYC = pytz.timezone('America/New_York')
    dt = datetime(2018, 2, 14, 12, tzinfo=NYC)
    print(dt)
    # 2018-02-14 12:00:00-04:56
How is that not a footgun?
thats horrific
Horrific in the Evil Dead sense, where it’s both horrific and really very funny.
> Wat. The author has no idea what a foot gun is.

In the article, "fastest" is italicized. The sentence is about whether the footgun is fast, not whether the footgun is a footgun.

Did you read the article? The author explains exactly why they think Pytz is not enough, and why they think dateutil.tz (not the standard library) is a better alternative.
To be clear, when I wrote this article, I had not yet created the `zoneinfo` module in the standard library. All the recommendations for `dateutil.tz` apply to `zoneinfo` as well, except that `zoneinfo` is also faster than `pytz`.
Thank you so much for your work on zoneinfo. I spend my days working on a legacy Django app and can't wait to switch from pytz to zoneinfo. In my experience, timezones are always a struggle so your efforts to make them easier to deal with is hugely appreciated.