Data Cleaning Exercises

Exercise · intermediate · 15 min

Timestamps need an offset

Normalize timestamps to UTC, keep two different offsets on the same wall-clock time apart, and quarantine timestamps that never said which zone they're in.

The rules

These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.

Input
  events(id, raw_ts) — text. id is unique.

Rules
  Accept raw_ts when it is YYYY-MM-DD, "T" or one space, HH:MM[:SS[.fraction up to 6 digits]], then an explicit
  offset (Z or ±HH:MM, at most ±14:00); hour 00–23, minute/second 00–59; the date must exist. Convert to UTC.
  2026-11-01T01:30:00-04:00 and 2026-11-01T01:30:00-05:00 are different instants.
  Quarantine with reason:
    missing_offset   a well-formed date and time with no offset (never assume a zone)
    bad_timestamp    anything else, including missing values

Outputs (row order does not matter)
  clean(id text, ts timestamptz [UTC])
  exceptions(id text, reason text)

The data

events · 11 rows

idraw_ts
evsk9z2026-01-15T09:00:00+15:00
evp3vk2026-11-01T05:30Z
evs5xu2026-06-30T23:59:59.123456
eve3p8yesterday
evl74h2026-06-30T23:59:59.5+05:30
evff5w2026-11-01T01:30:00
evdtw22026-11-01T01:30:00
evfs8g2026-01-01T00:00:00+14:00
evwupf2026-11-01 01:30
evbd2o2026-11-01T01:30:00
ev6p6c2026-11-01 01:30

What you practise

  • timestamps
  • time zones
  • quarantine

Your answer is also checked on hidden datasets generated from the same rules.

Download this dataset (CSV) with its data dictionary

Sign in to bookmark this and keep private notes.