How to get the user's local timezone in Workshop as a variable/parameter?

I’m looking to create a custom string dropdown made from a list of local timestamps for the user. There are set amount of timestamps related to the object, so the generic timestamp filters don’t suit our needs.

I understand that there are:

  1. Built-in filter widget that lets you specify a histogram and range.
  2. Date and time picker widget.

But I would like to create a dropdown of specific local timestamps for the user. In order to do so, I would need one of these solutions, or another feature:

  1. Some sort of method to cast an array of timestamps strings in Workshop.
  2. Pass in the timezone offset of the user into the Function that creates a string of local timestamps.

For such a custom behaviour you could use typescript functions. You would have a string selector for the timestamps, another one for the list of timezones, and you would pass the selected values to a typescript function where you can cast the strings and have all the flexibility you need.

And you could get this list of timezones from another function which would rely on the moment.js library for instance (https://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/).

I figured this would be the only way to do it. Ideally I’d like to grab the user’s timezone automatically and skip the extra string selector for the timezone, but there doesn’t seem to be a pathway to do that. For example the Date & Time Picker automatically displays a timezone on the Frontend

It is not possible to get the local timezone from typescript functions since they’re not executed in the browser. If it is not possible in Workshop for now, one hacky workaround could be to iframe a hidden Slate application which would get the local timezone in a Slate function and output it to the Workshop module.

1 Like

For any future readers, I ended up going this route with a hidden slate embed. I grabbed the

  1. Get the timezone name from running local javascript in the Slate/Advanced Code Widget
  2. Slate.sendmessage() of the timezone name to Workshop
  3. Pass the timezone name variable from Workshop as a parameter to a Function
  4. Used the timezone name to convert the UTC timestamps to local time. This handles the correct offsets for shifted daylight savings time in historical dates as well, enabling me to have a local timestamp string selector.