top | item 35914354

(no title)

bhargav | 2 years 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.

discuss

order

Twirrim|2 years ago

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?

steveBK123|2 years ago

thats horrific

Joeboy|2 years ago

> 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.

roelschroeven|2 years ago

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.

pganssle|2 years ago

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`.