Skip to content

Conversation

Xiticks
Copy link

@Xiticks Xiticks commented Aug 23, 2025

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

    • Date and time fields now display and autofill in your local timezone (e.g., “Now” and “+1 hour”), improving clarity when creating visits.
  • Bug Fixes

    • Prevents unexpected time shifts after saving by converting locally entered dates/times to UTC before sending to the server, ensuring consistent start and end times across time zones.
  • Improvements

    • Minor UI consistency updates to date/time handling for a smoother form-filling experience.

Copy link

coderabbitai bot commented Aug 23, 2025

Walkthrough

Implements 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

Cohort / File(s) Summary
Manual visit datetime handling
app/javascript/controllers/add_visit_controller.js
- New pad() and formatDateTime() for local YYYY-MM-DDTHH:mm
- Defaults use local time for start/end inputs
- Added localToUTCISOString() and applied on submit for started_at/ended_at
- Switched to consistent string quotes; minor formatting

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Preserve manual visit times as entered; prevent timezone-induced shifts (#1679)
Ensure both started_at and ended_at are correctly handled on submit in UTC (#1679)

Poem

I nibble on code in the midnight glow,
Turn local ticks to UTC flow.
No hopping hours, no temporal fright—
Your visits now land just right.
Thump-thump! says my reviewy paw,
Time’s aligned—no bunny’s in awe. 🐇⏰

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 4b80f77 and b005abd.

📒 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 detected

I’ve verified that the only runtime usage of new Date("YYYY-MM-DDTHH:mm") for <input type="datetime-local"> occurs in add_visit_controller.js, and your explicit-parsing diff correctly addresses cross-browser and DST concerns. All other new Date('YYYY-MM-DDT…') usages were found exclusively in e2e/live-mode.spec.js static test fixtures, so no additional production code changes are needed.

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.

Manual Visit Creation Time Change
1 participant