q.pfiffer.org - A Random Python Timezone Bug

Malevolent Cartography Write C Drink your coffee black Sleep on the floor github.com/qpfiffer qpfiffer@gmail.com +1(503) 985-6583 All Posts Nav 2020-03-12 by Quinlan Pfiffer So this one is another interesting Python Timezone thing. It feels like every time I do something with timezones in Python, I think I've got them figured out and I clearly don't. Theres always another thing. This one was interesting though and took a while to figure out. The issue turned out to be not as straight-forward as I thought it would have been. Imagine something like this: from datetime import datetime, timezone import pytz TIMEZONE = "US/Eastern" tz = pytz.timezone(TIMEZONE) def utc_now(): return datetime.now(timezone.utc) def tz_now(): return convert_to_local(get_utc_now()) def convert_to_local(any_time): return any_time.astimezone(tz) def convert_to_utc(any_time): return any_...

Linked on 2020-03-13 00:17:26 | Similar Links