Two logs can describe the same instant with different local times. Sorting their timestamp strings without considering offsets can put events in the wrong order. A useful timeline preserves the original timestamp, normalizes a comparable value and records what is known about the source clock.
An offset-aware timestamp identifies its relationship to UTC. A naive timestamp does not. Do not silently assume that every source uses your laptop time zone. If a source omits the zone, document the assumption and the evidence supporting it before normalizing.
from datetime import datetime, timezone
def to_utc(text):
value = datetime.fromisoformat(text)
if value.tzinfo is None:
raise ValueError("timestamp needs an offset")
return value.astimezone(timezone.utc)
india = to_utc("2026-09-01T10:00:00+05:30")
utc = to_utc("2026-09-01T04:30:00+00:00")
assert india == utc
print(india.isoformat()) # 2026-09-01T04:30:00+00:00Keep the source artifact identifier, original timestamp, parsed offset, normalized value, event description and parsing method. A timeline should let a reviewer return to the original record. If you correct a known clock offset, store that as an explicit transformation rather than replacing the raw value.
A log may print milliseconds while its clock is several seconds wrong. Fine formatting does not establish accurate time. Events closer together than the known uncertainty may not have a defensible order. Treat equal timestamps as potentially simultaneous or unresolved rather than inventing an ordering.
A fixed numeric offset and a named time zone answer different questions. Historical local times can be ambiguous or nonexistent around daylight-saving transitions. When a source records only local time, determine the relevant zone and transition rules instead of applying the current offset retroactively.
A login followed by a file change is a temporal observation, not automatic proof that the login caused the change. Correlate identifiers, application behavior and additional evidence. Explain missing records and retention gaps so the timeline does not appear more complete than the sources allow.
Create three offset-aware sample events representing two distinct instants. Normalize and sort them while preserving the raw values. Add a naive timestamp and confirm your parser rejects it until an assumption is documented.
Explore the related Code Hacker course syllabus for structured learning. Then read Build a Digital Evidence Manifest for a Practice Case to connect this exercise to the next skill.
Python datetime documentation provides the underlying API or technical guidance. Check the documentation for the version you use; examples here are small learning exercises rather than complete production implementations.
Found an issue with this guide? Send a correction with the article URL and your example. About our learning material.
Subscribe to Code Hacker and get hands-on access to 40+ premium courses — Ethical Hacking, Kali Linux, Metasploit, Network Hacking, Bug Bounty & more!