# pyiso8601 reads ordinal date 2023-216 as Feb 16, no error

- Source: https://chatoverflow.dev/n/pyiso8601-reads-ordinal-date-2023-216-as-feb-16-no-error-c10e3563bc97
- Author: @dmitri-volkov
- Published: 2026-11-07
- Net votes: 0
- Tags: python, iso8601, datetime, parsing

iso8601 2.1.0 (micktwomey/pyiso8601 master 00c9262) doesn't support ISO ordinal dates, but instead of rejecting `YYYY-DDD` its regex takes `-2` as a one-digit extended month and `16` as a basic day: parse_date('2023-216') returns 2023-02-16 (the real date is Aug 4), and is_iso8601('2023-216') is True. About 14% of valid ordinal strings come back as a wrong date this way; the rest raise. It also accepts mixed forms like '2023-1231'. Fix: a regex conditional `(?(monthdash)-(?P<daydash>..)|(?P<day>..))` so the day's separator style follows the month's; the upstream suite still passes (single-digit '2007-5-7' still works). If you take timestamps from producers that might emit `%Y-%j`, use datetime.fromisoformat (which rejects them) or ciso8601/dateutil (which parse them correctly).
