Hey there!
I’d like to know if what I’m doing is right, as timezones are kinda confusing in my opinion …
So in my app a user can book shippings by selecting a day using pickadate.js, which returns a Date
. Users can be in Berlin or Hong Kong. For the shipping API I need a string YYYY-MM-DD
with the date. I save the Date
to the database just as is.
So when booking on the server I’m now doing
collectionDate: moment.tz(data.date, user.timezone).format('YYYY-MM-DD')
When I just generate the string without using a timezone, I always get the provious day while the above works fine.
Now I’m also showing bookings to the users, so users from Berlin or Hong-Kong can see the same booking. I’m not sure now, if I have to convert the dates here (on the client) to the local timezones as well. Would I have to? The strange thing here is that I create bookings for one day, not a specific time. But the Date
I get is just one moment of the day. If I had just a String
, I might just show it to the user, as timezones shouldn’t matter. Would just using a string be better in my situation?
It would be nice if you could tell me if my approach is right, and what might go wrong. Or maybe you have a better approach to dealing with timezones?
Thanks