PythiloLesson 3 of 8 · progress kept in this browser

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