feat: late-night cutoff for calendar bucketing#221
Merged
Conversation
Late-night shows (start time before 5am) now display under the previous calendar day, matching how humans actually think about nightlife. A 1am Sunday show is 'Saturday night' — its calendar group key shifts back a day, but the underlying start_datetime never changes. Single- event pages, structured data, ICS exports, and any datetime-aware consumer still see the real start time. The cutoff hour is filterable via 'data_machine_events_late_night_cutoff_hour' (default 5, matching Bandsintown / Songkick — RA uses 6). Set to 0 to disable. Values >= 12 are clamped to the default to prevent absurd configurations. The cutoff applies in two places: - DateGrouper::group_events_by_date() shifts single-day grouping keys for the calendar list/grid views - CalendarAbilities::compute_unique_event_dates() applies the same shift at the SQL layer (DATE(start_datetime - INTERVAL 5 HOUR)) so per-day bucket counts match the displayed grouping Multi-day events are not shifted — they already span multiple calendar days regardless. The continuation/start-day flags use an effective start date so cutoff-shifted events still render as their own day's 'start day' rather than a continuation of the previous night. The cutoff hour is folded into the calendar cache key so toggling the filter at runtime invalidates stale buckets. Verified against extrachill.com data: HollyRock 1am Sat → Friday Apr 24, LATE SHOW SAT: Kaytraaaa! Club! 12:30am Sun → Saturday Apr 25.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Late-night shows (start time before 5am) now display under the previous calendar day, matching how humans actually think about nightlife. A 1am Sunday show is "Saturday night" — its calendar group key shifts back a day, but the underlying `start_datetime` never changes.
Why
Caught while auditing post-deploy. Example from production:
HollyRock — Late Night at Gasa Gasa, New Orleans. Body copy reads "Late show beginning at 1:00 AM local time on 2026-04-25. This performance is listed as a late show for April 24, 2026 (technically after midnight)." But the calendar files it under Saturday Apr 25 because that's the literal datetime.
Same pattern for ~10 NOLA late-night shows scraped from Ticketmaster. Real shows, real times, just bucketed wrong for human consumption. New Orleans pushes this hard — 1am, 2am, even 4am sets are routine.
Behavior
The cutoff hour is filterable:
```php
add_filter( 'data_machine_events_late_night_cutoff_hour', fn() => 6 ); // RA convention
add_filter( 'data_machine_events_late_night_cutoff_hour', fn() => 0 ); // disable
```
Default 5 matches Bandsintown / Songkick. RA uses 6. Values `>= 12` are clamped to the default.
What changed
The data layer is untouched. `start_datetime`, post URL, slug, structured data, ICS exports — all unchanged.
Verification
Smoke test: 19 cases pass (including month/year rollovers, midnight exact, no-time fallback, filter disable, RA-convention 6am cutoff).
Live SQL check on `events.extrachill.com`:
```
HollyRock 1am Sat 2026-04-25 → display_date 2026-04-24 (Friday)
LATE SHOW SAT: Kaytraaaa 12:30am Sun → display_date 2026-04-25 (Saturday)
Greyboy Allstars 2am Sun → display_date 2026-04-25 (Saturday)
Motown Throwdown 1:30pm Sun → display_date 2026-04-26 (Sunday) ← unchanged
MJT 7:30pm Sun → display_date 2026-04-26 (Sunday) ← unchanged
```
Out of scope
Some events stored with `startTime = 00:00:00` are AI extraction failures (e.g. "Surf Sunday Brunch" stored as 00:00 when content says 11am). These get shifted by the cutoff, which is technically correct for the bad data — but the underlying extraction quality bug is separate work, not blocked by this PR.