Fix live-tracking indicator using server time zone for daytime check#358
Merged
Conversation
`event_live_tracking_tag` highlights/pulses an event only while it's "in progress", which requires `is_daytime?` to be true. With no `@weather` in the events context, `is_daytime?`/`is_evening?` fell back to `Time.now`, i.e. the server's system zone (UTC in production), instead of the location's local time. At 2pm in a UTC-7 location that's 21:00 UTC, so the daytime check failed and the icon never went live. Read the fallback clock in the location's timezone via `current_time`, and update the specs/comments that encoded the old system-zone behavior.
✅ Deploy Preview for giventotri canceled.
|
The "in progress" check (which highlights and pulses the Live tracking link) depends on it being daytime. We already fetch race-day weather for the featured event — the only event whose tracking tag renders — so prefer its own sunrise/sunset over the owner's-location clock. `is_in_progress?` now takes the featured event's weather presenter and, when its sun times are present, treats the event-day sunrise..sunset window as the source of truth: covering "now" means it's both the event's day and daytime at the event's location (the sun times are absolute instants, so the comparison is timezone-independent). It falls back to today-and-daytime in the owner's timezone when that weather isn't available. The tag and the upcoming-races partial thread the presenter through.
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.
The bug
The "Live tracking" indicator (
event_live_tracking_taginapi/app/helpers/events_helper.rb) only highlights and pulses while an eventis_in_progress?, which requiresis_daytime?to be true. In the events context there's no@weather, sois_daytime?(andis_evening?) fell back to the wall clock usingTime.now— the server's system zone, which is UTC in production on fly.io — rather than the event location's local time.So at 2:00 PM in San Francisco (UTC-7 → 21:00 UTC),
now.hourwas21, the>= 6 && < 18daytime check failed, and the icon never switched to its live/pulsing state. (The weather-present branch was fine — it compares absolute instants — only the no-forecast.hourfallback was wrong.)The fix
Read the fallback clock in the location's timezone via
current_time(Time.current.in_time_zone(location_time_zone)) in bothis_daytime?andis_evening?. The absolute-instant sunrise/sunset comparisons are unchanged in meaning.Specs and comments that had encoded the old system-zone fallback are updated: the no-weather daytime/evening fallback test now freezes a fixed UTC instant and asserts against the Denver-local hour, so it's deterministic regardless of where the suite runs.
Testing
spec/helpers/weather_helper_spec.rb+spec/helpers/events_helper_spec.rb: 114 examples, 0 failures.plausible_pageviews_speccache-header assertions, unrelated to this change (confirmed failing on the base branch).https://claude.ai/code/session_01PNfLfKdfrvvM5jTWYT9WQc
Generated by Claude Code