Exercise · intermediate · 20 min
Parse dates by declared locale
03/04/2026 is March 4th in the US and 3 April in the UK. Parse slash dates only when the row says which convention it uses.
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_date, locale) — text. id is unique. locale may be missing.
Rules
Accept raw_date when it is:
- an ISO date YYYY-MM-DD (any locale, including missing), or
- a slash date D/M/YYYY or M/D/YYYY (1–2 digit day and month) AND locale is
en-US → month first, or en-GB → day first.
Quarantine with reason:
invalid_date raw_date is missing, or a slash date with a declared locale names a day that does not exist (31/02/2026)
ambiguous_format anything else, including a slash date whose locale is missing or not en-US/en-GB
Outputs (row order does not matter)
clean(id text, date date)
exceptions(id text, reason text)The data
events · 8 rows
| id | raw_date | locale |
|---|---|---|
| evvsoj | 04/08/2025 | en-GB |
| evkcwt | 02/12/2025 | en-GB |
| evsig0 | 2025-06-05 | en-US |
| evrwhn | 6/20/2025 | missing |
| evsr70 | 05/12/2025 | en-GB |
| eva355 | 2026/04/03 | en-GB |
| evnf0z | 13/13/2026 | en-GB |
| eve734 | 01/03/2026 | en-US |
What you practise
- dates
- locales
- quarantine
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.