Code RoomAmbiguous local time converts wrong
HardPrep Room Coding #1959

Ambiguous local time converts wrong

Code reviewCode quality & reviewSenior–Staff~22 min

Review this Python code that converts a logged local timestamp to UTC for storage (drivers log in their local zone).

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 22 min
Mark a line and say what kind of problem it is.0 findings
1from datetime import datetime
2from zoneinfo import ZoneInfo
3 
4def to_utc(local_str, tzname):
5 # local_str like '2026-11-01 01:30:00', tzname like 'America/New_York'
6 naive = datetime.strptime(local_str, '%Y-%m-%d %H:%M:%S')
7 return naive.replace(tzinfo=ZoneInfo(tzname)).astimezone(ZoneInfo('UTC'))
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.