Skip to content

feat: support yyyy-MM-dd format for serviceDate in trip parameters#1070

Open
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trip-details_issue_3
Open

feat: support yyyy-MM-dd format for serviceDate in trip parameters#1070
3rabiii wants to merge 2 commits into
OneBusAway:mainfrom
3rabiii:fix-trip-details_issue_3

Conversation

@3rabiii

@3rabiii 3rabiii commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR addresses by enhancing the shared parseTripParams function to natively support calendar dates (yyyy-MM-dd) for the serviceDate parameter, conforming to the wiki spec.

Changes Included:

  • Native Parsing Logic: Upgraded parseTripParams to first attempt parsing the serviceDate as Unix milliseconds. If that fails, it falls back to parsing the string as a yyyy-MM-dd calendar date.
  • Timezone Safety: Crucially, calendar dates are parsed using time.ParseInLocation with the provided agency timezone (loc). This ensures "midnight" is calculated correctly relative to the agency's local time, preventing UTC-offset date-shift bugs. Defaults to UTC safely if no location is provided.
  • Refined Error Messaging: Updated the validation error to explicitly state: "must be a valid Unix timestamp in milliseconds or a date in yyyy-MM-dd format".
  • Testing:
    • Added TestParseTripIdDetailsParams_Unit/serviceDate yyyy-MM-dd format to verify accurate year/month/day extraction.
    • Added TestTripDetailsHandlerWithServiceDateString to integration test a full handler call with the calendar string format.

Fixes: #1054

Summary by CodeRabbit

  • New Features
    • Service dates can now be provided in user-friendly yyyy-MM-dd format, in addition to Unix timestamps in milliseconds. Calendar dates are interpreted using the agency’s local timezone.
    • Added coverage to confirm TripDetailsHandler correctly accepts serviceDate=YYYY-MM-DD and returns the expected service date value.
  • Bug Fixes
    • Updated validation/error messaging to reflect the expanded accepted serviceDate formats.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a3a6cc30-d005-47e6-a556-9fb3f52594db

📥 Commits

Reviewing files that changed from the base of the PR and between 5e12050 and 35e0970.

📒 Files selected for processing (1)
  • internal/restapi/trip_details_handler.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/restapi/trip_details_handler.go

📝 Walkthrough

Walkthrough

parseTripParams in trip_details_handler.go is updated to accept serviceDate as either a Unix millisecond timestamp or a yyyy-MM-dd calendar date string, parsed in the agency's timezone (or UTC). The validation error message is updated, and new unit and integration tests confirm both formats work correctly.

Changes

serviceDate dual-format parsing

Layer / File(s) Summary
Dual-format serviceDate parsing and tests
internal/restapi/trip_details_handler.go, internal/restapi/trip_details_handler_test.go, internal/restapi/trip_for_vehicle_handler_test.go
parseTripParams now tries strconv.ParseInt first; on failure it attempts time.ParseInLocation with yyyy-MM-dd using loc[0] or UTC. The validation error message is updated to reflect both accepted formats. A unit subtest asserts correct year/month/day parsing, an integration test asserts HTTP 200 and timezone-adjusted midnight ServiceDate, and the trip_for_vehicle error assertion is updated to match the new message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #1054 – trip-details: serviceDate should accept yyyy-MM-dd format: This PR directly implements the requested behavior — accepting serviceDate=2024-06-15 as midnight in the agency's timezone alongside the existing Unix millisecond format.
  • trip-details: time parameter should accept yyyy-MM-dd_HH-mm-ss format #1055: Requests similar dual-format support for the time parameter (yyyy-MM-dd_HH-mm-ss), a parallel enhancement to parameter parsing in the same handler.

Possibly related PRs

  • OneBusAway/maglev#913: Modifies trip_details_handler_test.go serviceDate assertions and ServiceDate handling, directly overlapping with the test changes in this PR.

Suggested reviewers

  • fletcherw
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: adding support for yyyy-MM-dd date format in the serviceDate parameter.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #1054: supporting yyyy-MM-dd format for serviceDate with timezone-aware parsing and updated validation messages.
Out of Scope Changes check ✅ Passed All changes are directly related to the serviceDate format enhancement: handler logic, unit tests, and integration test validation updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/restapi/trip_details_handler.go (1)

95-109: 💤 Low value

Optional: Update comment to reflect yyyy-MM-dd behavior.

The comment explains why localization is needed for Unix millisecond parsing (preventing UTC date-extraction bugs), but doesn't mention that for yyyy-MM-dd dates, this block is a no-op since time.ParseInLocation at line 49 already parses in the target timezone. Consider adding a note that yyyy-MM-dd dates are already localized at parse time.

📝 Proposed comment update
 // If a timezone location was provided, localize serviceDate and time so that
 // callers receive times in the agency's timezone by default. This prevents the
 // bug where time.Unix(ms/1000, 0) creates a UTC time and downstream
 // Year()/Month()/Day()/Format() calls extract the wrong calendar date for
-// agencies in positive UTC offsets.
+// agencies in positive UTC offsets. For yyyy-MM-dd dates, this is a no-op since
+// they are already parsed in the correct timezone at line 49.
 if len(loc) > 0 && loc[0] != nil {
🤖 Prompt for 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.

In `@internal/restapi/trip_details_handler.go` around lines 95 - 109, Update the
comment block that precedes the timezone localization logic (starting around the
"If a timezone location was provided" text) to clarify that while the comment
explains why localization is necessary for Unix millisecond parsing to prevent
UTC date-extraction bugs, yyyy-MM-dd formatted dates are already localized at
parse time via the time.ParseInLocation call at line 49, making this
localization block a no-op for those dates. Add a note explaining that this
block primarily handles the Unix millisecond case.
🤖 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.

Nitpick comments:
In `@internal/restapi/trip_details_handler.go`:
- Around line 95-109: Update the comment block that precedes the timezone
localization logic (starting around the "If a timezone location was provided"
text) to clarify that while the comment explains why localization is necessary
for Unix millisecond parsing to prevent UTC date-extraction bugs, yyyy-MM-dd
formatted dates are already localized at parse time via the time.ParseInLocation
call at line 49, making this localization block a no-op for those dates. Add a
note explaining that this block primarily handles the Unix millisecond case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 510b6872-fb77-4504-935d-c5d02c813ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 9898b8f and 5e12050.

📒 Files selected for processing (3)
  • internal/restapi/trip_details_handler.go
  • internal/restapi/trip_details_handler_test.go
  • internal/restapi/trip_for_vehicle_handler_test.go

@sonarqubecloud

Copy link
Copy Markdown

@3rabiii 3rabiii requested a review from burma-shave June 14, 2026 22:31
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.

trip-details: serviceDate should accept yyyy-MM-dd format

1 participant