In fact, adding a timezone setting becomes inevitable once you realise the complexity you’ll need to deal with especially if you’re a SaaS app that has customer organisations with users in many timezones.
Since your server will be the ground truth for all clients, it’s best to set it to the UTC timezone. To do this there are a few places you’ll have to set timezones:
TZand you’re good to go.
TZvariable to the cypress script.
After much trial and error this is the simplest setup I have come up with:
On the frontend, when submitting data adjust the time to UTC before sending it. You can do so on
const data = parseForm(someForm); data.someDate = zonedTimeToUTC(data.someDate, app.timezone);
On the backend, you can process and store data normally without making any changes to the form handling.
It depends on two cases:
formatInTimezone(or the equivalent in other libraries)
Similar to the server we have two cases where the dates have to be handled differently
divor somewhere it is only displayed then use
formatInTimezoneto display in the store timezone.
utcToZonedTimeto convert the dateTime so it will be processed right.