Working on a problem where I have to evaluate whether a time stamp (UTC) exceeds 7PM Americas/New_York.
I naively did my check as:
if (timestamp - timedelta(hours=4)).time() > 19:
__logic__
Which obviously failed with daylight savings EST/EDT.
I think this works but feels wrong.
EST = pytz.timezone('America/New_York')
biz_end = datetime(1990, 1, 1, 19, tzinfo=EST).astimezone(pytz.utc).hour
if timestamp.time() > biz_end:
__logic__
Is there a better solution here?
It should be far simpler to work directly in desired TZ rather than fighting time differences and DST as this would mostly add a headache for no other benefits:
Also, if you use
pytzonly for this, you can use Python 3.9+ built-in libraries and droppytzdependency, which as @FObersteiner linked in above comment, would also free you from Weird timezone issue with pytz problems: