Understanding how time works.
Let say I live in Indonesia (UTC+7).
My server time is UTC.
My laravel setting is untouched.
Then I create a date picker for attribute in .
The event will be start in 14 October 2023 - 20:00 (8PM) INDONESIA TIME
So the user input 14 October 2023 - 20:00 (8PM) .
1. Should I modify data before saving to convet those time into UTC? or does laravel/filament/mysql detect this and automatically and convert it to UTC for me?
2. What if there's multiple user with different timezone?
Solution:Jump to solution
Always ALWAYS (always) always store UTC in the database. By which I mean always. Convert to whatever TZ you wish to display it in when rendering.
You can then either just have a single default TZ for your app (using APP_TIMEZONE in you .env), or you can allow your users to choose their TZ (app dependent, up to you how you let them select that) and use the ->timezone('foo/bar') method on all DateTimePicker fields (presumably getting the TZ from the auth()->user() object).
For table columns with per-user TZ I think you'd have to roll your own TZ offset with formatStateUsing(). And you'd probably have to do a little custom work on any date/time filters, if you needed those....
2 Replies
Solution
Always ALWAYS (always) always store UTC in the database. By which I mean always. Convert to whatever TZ you wish to display it in when rendering.
You can then either just have a single default TZ for your app (using APP_TIMEZONE in you .env), or you can allow your users to choose their TZ (app dependent, up to you how you let them select that) and use the ->timezone('foo/bar') method on all DateTimePicker fields (presumably getting the TZ from the auth()->user() object).
For table columns with per-user TZ I think you'd have to roll your own TZ offset with formatStateUsing(). And you'd probably have to do a little custom work on any date/time filters, if you needed those.