Different time zones in NodeJS / Server Connect

Hi,

I have a digital signage system built with Wappler using NodeJS. The system is used by several hotels located in different time zones in Mexico.

For example:

  • Cancun → America/Cancun
  • Mexico City → America/Mexico_City
  • Tijuana → America/Tijuana

Each hotel has multiple screens, and each screen displays information specific to that hotel, including a list of restaurants that are currently open.

The problem is that "open now" needs to be calculated using the hotel's local time, not the server time and not the local time of the device/browser displaying the signage.

For example, if I open a Cancun hotel's signage URL from Tijuana, it should still show the restaurants that are currently open according to Cancun time.

I have read the documentation about Server Time Zone, Database Time Zone Handling, and toLocalTime():

However, as I understand it, Server Time Zone is configured globally for the NodeJS target. In my case, a single Wappler application/server needs to handle multiple time zones simultaneously.

Ideally, I would like to store the IANA timezone in the hotel database table:

hotel_id | hotel_name    | timezone
1        | Cancun Hotel  | America/Cancun
2        | CDMX Hotel    | America/Mexico_City
3        | Tijuana Hotel | America/Tijuana

Then, in a Server Connect action, I would like to do something conceptually like:

Get Hotel
   ↓
hotel.timezone
   ↓
Get current date/time in that timezone
   ↓
Filter restaurants that are open at that local time

I specifically want to use IANA time zones instead of fixed UTC offsets because locations such as Tijuana observe daylight saving time.

Is there a native/recommended way in Wappler Server Connect to get the current date/time for a dynamically specified IANA timezone, for example:

America/Tijuana

where the timezone value comes from a database query?

Or would the recommended approach be to create a custom NodeJS formatter/module using Intl.DateTimeFormat?

I would prefer to keep the logic server-side so the result does not depend on the timezone of the browser/device displaying the signage.

Thanks!

Just banged this out for you @Chackmool

You'll be the guinea pig. Please read the readme document for installation instructions and let me know if it works for you then will push it to npm.

You'll add a Query Step, then WhereNow Step after that to select the IANA time variable you have stored in your database from the Query Step results.

Hi Cheese,

This looks like a really handy extension! If I’ve got it right, it’ll need the local time zone to work out the different whereNow binding outputs. Is that correct?

Yes in the IANA format as @Chackmool requested, example: America/Tijuana.

Requires an IANA timezone (e.g. America/Tijuana, Europe/Lisbon) on the step. That is what drives all the outputs: localDate, localTime, hour, minute, dayOfWeek, and the rest.

What “local” means here is local to the timezone you bind, not:

  • The Node server’s OS timezone.
  • The visitor’s browser timezone.

Typical pattern:

Get Hotel → returns hotel.timezone (IANA).

Where Now → timezone = {{hotel.timezone}}

Filter → open_from <= {{whereNow.localTime}} AND close_after >= {{whereNow.localTime}}

So if the hotel is in Tijuana, you pass America/Tijuana and you get Tijuana’s current date/time (DST included).

:slight_smile:

Feel free to try and provide some feedback if you can as I don't have a use-case for it right now. We have custom formatters for all this stuff on our back-end already in-place. If it all works as intended I'll push it to npm as a Wappler Extension to satisfy those that don't want to use Git or don't know how to...