How to deal with timezones using DatePicker in Filament v2

I am using the following code:
DatePicker::make('start_date')
->label(fn (Closure $get, $record) => 'Date' . ' ($record->start_date=' . $record->start_date . ')')
->formatStateUsing(fn () => today())
->required();
DatePicker::make('start_date')
->label(fn (Closure $get, $record) => 'Date' . ' ($record->start_date=' . $record->start_date . ')')
->formatStateUsing(fn () => today())
->required();
When I select 20th of October, it will save as 20th of october (yay! 🥳). However, when I do not modify the date at all, and save the form, the date will be the one from formatStateUsing, but subtracted by 1 day. This issue does not occur when using the following code with ->timezone('UTC'):
DatePicker::make('start_date')
->label(fn (Closure $get, $record) => 'Date' . ' ($record->start_date=' . $record->start_date . ')')
->formatStateUsing(fn () => today())
->required()
->timezone('UTC');
DatePicker::make('start_date')
->label(fn (Closure $get, $record) => 'Date' . ' ($record->start_date=' . $record->start_date . ')')
->formatStateUsing(fn () => today())
->required()
->timezone('UTC');
In my model:
protected $casts = [
...,
'start_date' => 'date:Y-m-d',
]
protected $casts = [
...,
'start_date' => 'date:Y-m-d',
]
My local timezone:
jordy@MacBook % date +"%Z %z"
CEST +0200
jordy@MacBook % date +"%Z %z"
CEST +0200
config/app.php -> 'timezone' => 'Europe/Amsterdam', I find it strange that the timezone has anything to do with this, as this is a date picker, not date time. Plus, my model is cast as date, not date time. Dates should not differ based on timezone. Is this a bug, feature or am I missing something?
No description
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server