-
-
Notifications
You must be signed in to change notification settings - Fork 202
Fix UTC/Local time issue when creating a visit #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughImplements local-time formatting for datetime inputs and converts submitted times to UTC before sending to the API. Introduces helpers for padding and local-to-UTC conversion, updates default start/end time initialization, and adjusts form submission to use UTC ISO strings. Minor non-functional formatting edits included. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant C as AddVisitController (Browser)
participant API as Server API
U->>C: Open Add Visit form
activate C
C->>C: Compute now & +1h in local time
C->>C: formatDateTime(now), formatDateTime(+1h)
C-->>U: Prefill datetime-local inputs (local)
U->>C: Submit form (name, started_at, ended_at, lat, lng)
C->>C: localToUTCISOString(started_at), localToUTCISOString(ended_at)
note right of C: New: Convert local input to UTC ISO
C->>API: POST /visits { started_at(UTC), ended_at(UTC), ... }
activate API
API-->>C: 201 Created + payload
deactivate API
C-->>U: Show created visit details
deactivate C
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
app/javascript/controllers/add_visit_controller.js (3)
207-212
: Local datetime formatting for datetime-local is correct; consider minor UX hardening.Good move switching to an explicit local formatter; this addresses the UTC display drift. As a small UX nit:
- Consider explicitly specifying step="60" on the datetime-local inputs to make "minute" precision explicit and avoid seconds creeping in via some browsers.
- Optionally zero-out seconds/millis on the defaults before formatting for consistency near second boundaries.
Example (outside current hunk):
<input type="datetime-local" ... step="60" />Optionally:
now.setSeconds(0, 0); oneHourLater.setSeconds(0, 0);
305-310
: Trim name and send numeric lat/lng to match API expectations.Minor payload hygiene: trim the name to prevent accidental leading/trailing spaces and cast coordinates to numbers so the backend receives numeric types. If your API strictly expects strings, skip the numeric casts.
- name: formData.get("name"), + name: (formData.get("name") || "").trim(), started_at: localToUTCISOString(formData.get("started_at")), ended_at: localToUTCISOString(formData.get("ended_at")), - latitude: formData.get("latitude"), - longitude: formData.get("longitude"), + latitude: parseFloat(formData.get("latitude")), + longitude: parseFloat(formData.get("longitude")),
207-212
: Optional: enforce end ≥ start in the UI for immediate feedback.In addition to the runtime check, you can set min on the end field and keep it synced with the start field to guide users.
Example (outside current hunk):
<input type="datetime-local" id="visit-start" name="started_at" required value="${startTime}" step="60"> <input type="datetime-local" id="visit-end" name="ended_at" required value="${endTime}" step="60" min="${startTime}">And after mounting the popup (outside current hunk):
const startEl = document.getElementById("visit-start"); const endEl = document.getElementById("visit-end"); if (startEl && endEl) { const syncEndMin = () => { endEl.min = startEl.value; }; startEl.addEventListener("input", syncEndMin); syncEndMin(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
app/javascript/controllers/add_visit_controller.js
(3 hunks)
🔇 Additional comments (2)
app/javascript/controllers/add_visit_controller.js (2)
469-469
: No-op change.Trailing brace looks fine; nothing to flag here.
297-301
: LocalToUTCISOString refactor applied; no other dynamic Date(string) parsing detectedI’ve verified that the only runtime usage of
new Date("YYYY-MM-DDTHH:mm")
for<input type="datetime-local">
occurs inadd_visit_controller.js
, and your explicit-parsing diff correctly addresses cross-browser and DST concerns. All othernew Date('YYYY-MM-DDT…')
usages were found exclusively ine2e/live-mode.spec.js
static test fixtures, so no additional production code changes are needed.
Fixes the date displayed when creating a visit, now based on local time instead of UTC
Keep the save in UTC
Closes #1679
Summary by CodeRabbit
New Features
Bug Fixes
Improvements