Skip to content

Date-only values parse to midnight; time-only pickers validate against their format - #161

Open
grafst wants to merge 1 commit into
coolsam726:mainfrom
blemli:date-only-and-time-only-fixes
Open

grafst wants to merge 1 commit into
coolsam726:mainfrom
blemli:date-only-and-time-only-fixes

Conversation

@grafst

@grafst grafst commented Sep 29, 2026

Copy link
Copy Markdown

Two things found when moving an app's date and time fields to this field:

  1. A date-only picker changes the record on every save. parseToCarbon() uses Carbon::createFromFormat($format, …), and without the ! prefix PHP fills every field the format leaves out with the current clock time: Y-m-d → 2026-10-06 02:45:40. The dehydrated Carbon then differs from the stored 2026-10-06 00:00:00, wasChanged('day') is true on every save, and anything hooked on that (in our case a «date moved» customer notice) fires although the user only edited another field. With '!'.$format a date-only value lands on midnight and a time-only value on the epoch date.

  2. Time-only pickers fail validation. timePicker() keeps the date rule (hasDate() stays true), and Laravel's date rule rejects a bare 14:00 («must be a valid date»). Time pickers now validate as date_format:<their format> instead.

Tests cover both (dehydration to midnight, H:i passing and 14:60 failing).

🤖 Generated with Claude Code

…t their format

createFromFormat() without «!» keeps the current clock time for every field
the format leaves out, so a date-only picker saved «2026-10-06 02:45:40» —
and the record's date column changed on every save although the user never
touched it. The «!» prefix resets those fields.

Laravel's «date» rule refuses a bare time («14:00»), yet timePicker() kept
that rule: time-only pickers now validate as date_format:<their format>.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant