Skip to content

Support flexible datetime formats in job creation/update forms#38

Open
knutties wants to merge 1 commit into
mainfrom
claude/keen-cerf-gc48aq
Open

Support flexible datetime formats in job creation/update forms#38
knutties wants to merge 1 commit into
mainfrom
claude/keen-cerf-gc48aq

Conversation

@knutties

@knutties knutties commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR improves the user experience of the job creation and update forms by accepting flexible datetime formats from HTML <input type="datetime-local"> elements, while also standardizing API error responses for malformed JSON requests.

Key Changes

  • Added flexible datetime deserialization module (flexible_datetime in job.rs):

    • Accepts both RFC 3339 timestamps (e.g., 2026-06-09T17:18:00Z) and HTML datetime-local values (e.g., 2026-06-09T17:18)
    • Treats timezone-less values as UTC
    • Replaces opaque "premature end of input" serde errors with clear, actionable error messages
    • Includes comprehensive unit tests covering all supported formats and error cases
  • Applied flexible datetime deserialization to timestamp fields:

    • CreateJob: run_at, starts_at, ends_at
    • UpdateJob: starts_at, ends_at
  • Standardized JSON deserialization error responses in the API:

    • Added json_error_handler to convert actix-web's default plaintext error messages into the structured { "error": { code, message, request_id } } format used throughout the API
    • Returns HTTP 400 (Bad Request) with consistent error shape for malformed JSON payloads

Implementation Details

The flexible datetime parser tries formats in order:

  1. RFC 3339 with timezone offset or Z suffix
  2. Datetime-local format with seconds (YYYY-MM-DDTHH:MM:SS)
  3. Datetime-local format without seconds (YYYY-MM-DDTHH:MM)

This allows the dashboard's job form to work seamlessly with HTML5 datetime-local inputs while maintaining backward compatibility with RFC 3339 timestamps from other clients.

https://claude.ai/code/session_01TYy8xee53T2SBYFf5ifgjq

Summary by CodeRabbit

Release Notes

  • New Features

    • Job scheduling now accepts flexible datetime input formats, including local datetime strings and optional fields that can be omitted or left empty.
  • Improvements

    • API now returns structured JSON error responses with error codes, messages, and request IDs for malformed JSON requests.

The dashboard's job form posts `datetime-local` values (e.g.
`2026-06-09T17:18`, no seconds, no offset) for `run_at`, `starts_at`,
and `ends_at`. chrono's default `DateTime<Utc>` deserializer only
accepts full RFC 3339, so these requests failed with the opaque
"Json deserialize error: premature end of input".

- Add a flexible deserializer for these fields that accepts both
  RFC 3339 (with offset/`Z`) and tz-less datetime-local values,
  interpreting the latter as UTC.
- Install an actix JsonConfig error handler so malformed bodies return
  the structured `{ error: { code, message } }` 400 the rest of the API
  uses, instead of actix's raw plaintext error.
@coderabbitai

coderabbitai Bot commented Jun 10, 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

Run ID: 2e8c9c31-3b17-4c40-a2a0-10990b50d472

📥 Commits

Reviewing files that changed from the base of the PR and between f44bf96 and 75c1b7b.

📒 Files selected for processing (2)
  • crates/api/src/main.rs
  • crates/common/src/models/job.rs

Walkthrough

This PR improves API request handling by adding a custom JSON error formatter and enabling job timestamps to accept dashboard-compatible datetime formats. The error handler structures malformed JSON responses; the flexible datetime module parses RFC 3339 or local datetime strings for job creation and updates.

Changes

API Request Handling Improvements

Layer / File(s) Summary
JSON payload error handler
crates/api/src/main.rs
Custom json_error_handler function intercepts JsonPayloadError and returns a structured JSON error response with code, message, and request ID; registered via web::JsonConfig::default().error_handler(...) in the Actix app.
Flexible datetime deserialization
crates/common/src/models/job.rs
Private flexible_datetime module accepts RFC 3339 timestamps or dashboard-emitted datetime-local strings (YYYY-MM-DDTHH:MM or YYYY-MM-DDTHH:MM:SS) as UTC; CreateJob and UpdateJob apply the deserializer to run_at and starts_at fields with serde default and deserialize_with attributes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Timestamps now bend to the dashboard's will,
And errors speak truth in JSON so chill,
Where flexible parsing meets error so clear,
The API improves, handlers are here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding support for flexible datetime formats in job creation/update forms, which matches the primary objective of accepting HTML datetime-local values alongside RFC 3339 timestamps.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/keen-cerf-gc48aq

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.

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.

2 participants