Skip to content

feat: late-night cutoff for calendar bucketing#221

Merged
chubes4 merged 1 commit intomainfrom
feat/late-night-calendar-cutoff
Apr 25, 2026
Merged

feat: late-night cutoff for calendar bucketing#221
chubes4 merged 1 commit intomainfrom
feat/late-night-calendar-cutoff

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Apr 25, 2026

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

Time Before After (cutoff=5)
Sun 01:00 files under Sun files under Sat night
Sun 02:30 files under Sun files under Sat night
Sun 04:59 files under Sun files under Sat night
Sun 05:00 files under Sun files under Sun
Sun 13:30 (brunch) files under Sun files under Sun
Sun 19:30 (regular show) files under Sun files under Sun

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

  • New `LateNightCutoff` helper class with a PHP API and a SQL expression builder
  • `DateGrouper::group_events_by_date()` shifts single-day grouping keys
  • `CalendarAbilities::compute_unique_event_dates()` applies the same shift via `DATE(start_datetime - INTERVAL 5 HOUR)` so per-day bucket counts match the displayed grouping
  • Cache key in `CalendarCache::generate_key()` folds in the cutoff hour so toggling the filter invalidates stale buckets
  • Continuation flags use an effective start date so cutoff-shifted events still render as their own night's "start day", not as a continuation of the previous evening

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.

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.
@chubes4 chubes4 merged commit bb41cec into main Apr 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant