Compare instants across timezone offsets
A timestamp with an offset identifies an instant, while a naive timestamp is only a wall-clock reading. Comparing timestamp strings can put the same instants in the wrong order. Parse aware datetimes, convert to UTC and compare their actual values. Reject missing offsets so the function never guesses the caller's local timezone.
from datetime import datetime, timezone
text = "2026-01-01T12:00+02:00"
x = datetime.fromisoformat(text)
print(x.astimezone(timezone.utc).hour)Think before coding
Converting an aware datetime preserves the instant and changes the wall-clock representation. Requiring an offset prevents machine-specific timezone settings from changing the answer. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write utc_hour(text): parse an ISO datetime, require a timezone offset, convert it to UTC and return its hour (0–23). Raise ValueError for a naive datetime. A trailing Z is valid.
The explanation opens here once every check passes.