NodeJS with Docker don't get local time

Wappler Version : 4.11
Operating System : macOS BigSur (M1)
Server Model: NodeJS
Database Type: MySQL
Hosting Type: Docker (local and remote)

Expected behavior

What do you think should happen?

Date should be correct in a Server Action.

Actual behavior

What actually happens?

Always shows UTC Time regardless of the used formatter

How to reproduce

  • Detail a step by step guide to reproduce the issue
  • A screenshot or short video indicating the problem
  • A copy of your code would help. Include: JS, HTML.
  • Test your steps on a clean page to see if you still have an issue

{"NOW":"2021-07-07T19:20:08","NOW_UTC":"2021-07-07T19:20:08","NOWtoLocalTime":"2021-07-07 19:20:08.000"}

I already deleted the lib directory and recreated it on restarting Wappler

I think that the docker image is set to utc time, so the local time and utc time are the same in there.

Thanks for the info. How would I get the real local time then :slight_smile: ?

What is the real local time? Server Connect uses the timezone configured on the server (docker image), App Connect uses the timezone on the client computer and the database uses the timezone configured in the database server.

I’m in Germany so 12:30 at the moment. Docker shows me it is 10:30 for NOW / NOW_UTC and NOW.toLocalTime()

For your information. It does work without Docker with a local NodeJS installation. It must be a Docker issue.

The docker image runs its own Linux OS and the timezone is default configured on UTC timezone. Just like on your computer the OS must be told which timezone it should use, it doesn’t know that it is located in Germany.

We don’t have a way to set it within Wappler. You probably have to edit the docker file directly to add it.

Thank you for the clarification. The problem is that it is pretty irritating if you start a new project with a local NodeJS installation and then want to use Docker. That means the toLocalTime formatter only works with a non NodeJS Docker installation.

If I understand your linked article correctly it would be possible to set a timezone on creation of the Docker container. Would it be a possible solution for Wappler if you could set a timezone per Project and use this to create the Docker container?

For everyone having a similar problem. I found a solution:

My local Dockerfile (under .wappler/targets/mylocaldocker) looks like this:

FROM wapplerio/node-14

ENV NODE_ENV development
WORKDIR /opt/node_app
COPY package.json .
RUN npm install --no-optional

ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

My remote Dockerfile (under .wappler/targets/myremotedocker) looks like this:

FROM wapplerio/node-14
COPY ./ /opt/node_app/

WORKDIR /opt/node_app
RUN npm install --no-optional --production

ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

@George, @patrick & @Teodor

Couldn’t you integrate this as an option with the project settings?

2 Likes

@patrick would it be possible to add the above to the project settings?

Good one, we will add options for this indeed.

2 Likes

New option is now available in Wappler 4 beta 13

1 Like

Thank you @George! It works great!

This topic was automatically closed after 2 days. New replies are no longer allowed.