Put evidence in a UTC window
Compare timezone-aware timestamps with an explicit inclusive start and exclusive end.
Same instant, different clocks
An event at 10:00+01:00 happened at the same instant as one at 09:00Z. Comparing the original strings can put them in the wrong order. Parse timestamps with datetime.fromisoformat() and convert aware values using astimezone(timezone.utc).
A timestamp without an offset is naive. It gives a clock reading without telling you which timezone produced it. This course rejects naive timestamps instead of assuming the timezone of your browser. That choice makes an investigation reproducible on another analyst's device.
Describe the boundary before writing the detector
Use a half-open window: include the start, exclude the end. Adjacent windows then meet without counting their shared boundary twice. In Python the comparison is start <= moment < end. Validate that the end is later than the start.
The function should preserve event order and leave original strings intact. A normalized value is useful for comparison; the original value is useful when tracing a finding back to an export. Later you will write normalized timestamps into a separate timeline.
Try an event exactly on each edge, one just before the start, and two equivalent timestamps with different offsets. These small examples reveal boundary mistakes more effectively than a long export whose correct answer is hard to inspect.
from datetime import datetime, timezone
a = datetime.fromisoformat("2026-04-01T10:00:00+01:00")
print(a.astimezone(timezone.utc).isoformat())
Put it into practice.
Define in_window(events, start, end). Return the original event dictionaries whose timestamp is at or after start and strictly before end, preserving order. All timestamp strings must parse and have a timezone offset (Z is accepted). Raise ValueError for naive/invalid timestamps or a nonpositive window. Do not change input records.
See an explained solution
from datetime import datetime, timezone
def parse_utc(value):
moment = datetime.fromisoformat(value)
if moment.tzinfo is None or moment.utcoffset() is None:
raise ValueError("Timestamp needs an offset")
return moment.astimezone(timezone.utc)
def in_window(events, start, end):
first, last = parse_utc(start), parse_utc(end)
if first >= last:
raise ValueError("Window must have a positive duration")
return [event for event in events if first <= parse_utc(event["timestamp"]) < last]
UTC conversion makes different offsets comparable. The exclusive upper edge prevents double counting between adjacent windows, and the function never rewrites evidence.