I build this web app for my son as his newborn gift 🎁 last year. My wife & I are obsessed with it since. We use it extensively every day until now on our phones, tablets, laptops, TVs, and even our Samsung fridge (required only internet & browser). I will release this to ALL parents in the world soon* for FREE. But now I want to allow my nephew & niece in Texas to use this dashboard/web app as a family test. I have to support diff timezone. Right now it only supports US ET which is where I live.
JJ's Dashboard
Desktop View (Read-only)
https://mybabies.app/baby/a4b7efe4-9c2f-4c48-b5b1-cc516a8f027f?code=N0Vk90
My config/app.php current set to 'timezone' => 'America/New_York',
I use moment.js a lot in the front-end to display my entire date/time logic.
to take the input as +2, +3, and so on.... so I can render the time based on that. I know I have to take user timezone as input and store that into the database as : +2, +3, ... . I've done that. I can also query back what user set as well. I just don't know what to do with that TZ. I'm afraid that I will change my codes in tons of places..
Is there a way to just detect user TZ just like we detect user dateTime? Should I consider that route instead ?
I think very optimistically... I got a timezone to work on my app now. Huge thanks to all the comments from everyone above, without you guys, I will never found the best working solution for my situation with such minimum changes.
First, I added 2 lines of code, I grab the client timezone
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; <<< ADDED : Line #1
Since I have already made an ajax on log pressed anyway, I just need to one more field to the server
var data = {};
data.tz = timezone; <<< ADDED : Line #2
Second, with 5 lines of code, I can access what I sent from FE like so to overwrite the created_at time.
$tz = $inputs['tz']; <<< ADDED : Line #3
$clientDate = new DateTime("now", new DateTimeZone($tz) ); <<< ADDED : Line #4
$clientTimestamp = $clientDate->format('Y-m-d H:i:s'); <<< ADDED : Line #5
$log = new BabyLog;
$log->type = $type;
$log->created_at = $clientTimestamp; <<< ADDED : Line #6
$log->updated_at = $clientTimestamp; <<< ADDED : Line #7
$log->save();
My database stored the right timestamp() based on my client device/browser.
No other codes needed, it just works.
I changed the Date & Time on my iPhone from Chicago to New York back and forth. I pressed log, it saved, and I noticed my front-end displayed the accurate time based on my client timezone now.
this post helps someone like me that wants to make their web-app work globally with minimal code changes. To be very specific in 7 lines of codes.