F
Filament12mo ago
KeyMe

DateTimePicker timezone issue

In an action, I have checkboxes where upon checking/un-checking, the corresponding datetimepicker field is set to now()->format('Y-m-d H:i:s') otherwise null. Casted the db fields to 'datetime'. Applied the timezone() method to use current user's timezone. Weird thing is, fields that are saved before and after applying timezone() are stored in database differently, the prior, stored in UTC & displayed as user timezone, the latter, stored in user's tz & displayed as UTC. On top of that, for fields stored as UTC in db, when i uncheck/re-check to fill new timestamp, it displays as UTC, is that normal? Below is the form:
Checkbox::make($checkbox)
->reactive()
->dehydrated(false)
->afterStateUpdated(fn ($get, $set) => $get($checkbox) ?
$set($col, now()->format('Y-m-d H:i:s')) : $set($col, null)
)
->formatStateUsing(function ($get) use ($col) {
return $get($col) ? true : false;
}),
DateTimePicker::make($col)
->timezone('Asia/Kuala_Lumpur')
->native(false)
->visible(function ($get, Model $record) use ($checkbox, $col) {
return $get($checkbox) || isset($record->fulfillment->$col);
}
)
->hiddenLabel(),
Checkbox::make($checkbox)
->reactive()
->dehydrated(false)
->afterStateUpdated(fn ($get, $set) => $get($checkbox) ?
$set($col, now()->format('Y-m-d H:i:s')) : $set($col, null)
)
->formatStateUsing(function ($get) use ($col) {
return $get($col) ? true : false;
}),
DateTimePicker::make($col)
->timezone('Asia/Kuala_Lumpur')
->native(false)
->visible(function ($get, Model $record) use ($checkbox, $col) {
return $get($checkbox) || isset($record->fulfillment->$col);
}
)
->hiddenLabel(),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server