fix: correct serviceDate for past-midnight trips - #1286
Conversation
- Map active trips to their actual service day's midnight instead of unconditionally using today's midnight. - Ensure trips resolved via previous-day service IDs correctly report yesterday's midnight. - Add test fixture and unit test to verify past-midnight service date assignment.
|
Warning Review limit reached
Next review available in: 33 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe trips-for-route handler now tracks the service-day midnight for each active trip. Responses use that trip-specific value, including trips from the previous service day that remain active after midnight. Tests add an overnight GTFS case and verify the returned ChangesService-date resolution
Estimated code review effort: 3 (Moderate) | ~15–30 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/restapi/trips_for_route_handler_test.go`:
- Around line 130-135: Add a separate previous-service-day fixture in the
trips-for-route tests with a non-empty block_id so it exercises the
block-selected assignment path in the trips-for-route handler rather than the
null-block path. Assert that the returned trip’s ServiceDate equals the previous
service-day midnight, and ensure the new fixture covers the newly introduced
branch or condition.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 010ebb25-cf37-473b-9572-ece873163ac8
📒 Files selected for processing (2)
internal/restapi/trips_for_route_handler.gointernal/restapi/trips_for_route_handler_test.go
Add a test fixture and unit test to ensure that past-midnight trips selected via the block path correctly report the previous service day's midnight as their ServiceDate.
|



Description
This PR fixes a logical bug in the
trips-for-routehandler where theserviceDatefor active trips was being unconditionally set to the current calendar day's midnight (todayMidnight).According to the GTFS API specification,
serviceDateshould represent the midnight at the start of the service day for the trip. For trips running past midnight (e.g., departing at 23:00 on Thursday and still active at 00:30 on Friday), the previous implementation incorrectly returned Friday's midnight instead of Thursday's.Changes Made
tripServiceDaymap to track the correct midnight timestamp for each active trip at the time it is resolved.prevServiceIDspath (previous-day null-block trips) and block-resolved active trips now correctly carry the midnight of their respective service day (prevDayMidnight).serviceDatefor each trip from the map instead of falling back to the current day's midnight.Testing
createTestApiWithOvernightFixturecontaining a Thursday-only service with a trip running from23:00to24:45.TestTripsForRouteHandler_PastMidnightServiceDate: Uses a mock clock set to Friday00:30 UTCto verify that the returnedserviceDatecorrectly reflects Thursday's midnight. All assertions pass cleanly.Closes: #1285
Summary by CodeRabbit
Bug Fixes
Tests