← Statpro dev log

The 11:30 PM kickoff that broke NFL week assignments

#data#sports#solo-founder

Two rows of four day tiles split by a dotted midnight line, with a glowing amber dot hopping across the line into the next tile.

An NFL game kicks off at 11:30 PM Eastern on a Sunday night. In local time that's Sunday. In UTC it's already Monday. If you sort games into weekly buckets by date, which of those two days are you using?

I had the wrong answer, and nothing told me. Statpro, my sports stats site, loads NFL games in batches called releases. Before one goes live, a validator checks it's complete and that each game sits inside the week the release covers. It filed that game under the wrong week, and the completeness check still passed.

A check that passed for the wrong reason

The validator compares each game's date against the start and end of its release week. If a game falls outside the week, it gets flagged. The trouble was which date it compared:

-- Old: compared the local game_date directly
AND (game.game_date < week.start_date
  OR game.game_date > week.end_date)

That game_date column had already been cast to a local date somewhere upstream. The 11:30 PM kickoff got a game_date of Sunday, while the kickoff in UTC was Monday. The boundary check saw Sunday and slotted the game into the earlier week.

The completeness check passed because the game existed. It just existed in the wrong bucket. Nobody noticed, me included, because most games kick off at sensible afternoon times, when the local date and the UTC date agree.

Compare the UTC kickoff, in plain sight

The new validator drops the pre-cast column and does the conversion inside the query, on the kickoff_at timestamp:

-- New: cast kickoff_at to a UTC date before comparing
AND ((game.kickoff_at AT TIME ZONE 'UTC')::date
    < week.start_date
  OR (game.kickoff_at AT TIME ZONE 'UTC')::date
    > week.end_date)

A timestamptz value stores one exact instant. AT TIME ZONE 'UTC' turns that instant into a plain timestamp as a UTC clock would show it, and ::date keeps the date part. The late Sunday game is now seen as a Monday kickoff in UTC, and it lands in the right week.

OLD compares the local game_date Kickoff 11:30 PM ET, Sunday Local date is Sunday Filed under Week 1 the completeness check still passed wrong week NEW casts kickoff_at to a UTC date Kickoff 11:30 PM ET, Sunday UTC date is Monday Filed under Week 2 right week
One kickoff, two dates. The old validator read Sunday and chose Week 1; the new one reads Monday in UTC and chooses Week 2.

The deeper problem with the old query is that a bare date has already thrown away its timezone. You can't tell from the column which midnight it was measured against. Casting from the timestamp inside the query puts that decision where a reviewer can read it.

One line of fix, sixty of discipline

The fix landed as two reviewed migrations. Each one is assertion-only and replay-safe, meaning it changes no stored data and running it twice does no harm: it replaces the previous completeness validator with the corrected version and does nothing else. A companion assertions file verifies the SQL is read-only, with no CREATE, INSERT or GRANT statements. A config file that records each migration's settings gets the new range. A release-contract test checks the exact SQL text, confirming the old local-date range is gone and the UTC range is present.

It's the same routine I use for every reviewed migration: generate the SQL, record where it came from, assert that the migration only asserts, and pin that config file. The fix itself was one line. The discipline around it was 60.

The rest of the afternoon

The week fix was one of nine commits hardening the NFL pipeline that afternoon. Four of the others changed how the data behaves.

Team profiles can now omit optional facts. Some teams don't publish a full fact sheet, and the validator had been treating the gap as a contract violation. The input that builds team pages now keeps each source's team abbreviations and normalizes aliases, so a team with several code variants projects consistently.

A new function counts how many team-record rows a stretch of the season should have, by deduplicating official team IDs across its games, where the old logic counted games. And the ordering of media records, meaning team and player images, is now pinned deterministically, so test fixtures don't flip on insertion order.

Silent wrong answers need loud checks

Every one of these is a small behavioral change wrapped in a reviewed migration and verified by a test that reads the exact SQL. The ratio of discipline to fix is high on purpose. This is the part of the product where a silent wrong answer is worse than a loud crash, and a game filed under the wrong week is exactly that: present, plausible and wrong.

This is the build log for Statpro (statpro.io) · All entries · Weekly essays