bastilimbach / docker-MagicMirror

Docker image for the Magic Mirror 2 project by Michael Teeuw.
https://hub.docker.com/r/bastilimbach/docker-magicmirror/
MIT License
185 stars 54 forks source link

Time of dates are wrong #15

Closed dersch81 closed 5 years ago

dersch81 commented 6 years ago

Hi, i have a quiet strange problem. All dates of the calendar are one hr in the future now in winter time. In the summer time it was 2 hrs.

I thought the time setting of the docker container is wrong. So i've started it now with -v /etc/localtime:/etc/localtime:ro to have the same time as the host.

checking with docker exec -it [ID] date confirms it.

But still the same problem. With a "normal" MM installation i don't have any problem like this.

How can this happen with the docker image?

bastilimbach commented 6 years ago

That’s strange. Are you using the default calendar? I’look into this. Thanks for reporting!

dersch81 commented 6 years ago

yes i'm using the standard calendar.

jhofker commented 6 years ago

For what it's worth, I added the following to the Dockerfile locally:

ENV TZ America/Chicago

RUN echo $TZ > /etc/timezone && \
    apt-get update && apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean

Rebuilt the image: docker build -t mm_tz .

And then ran it:

docker run -d --publish 80:8080 `
--restart always `
--volume ~/magic_mirror/config:/opt/magic_mirror/config `
--volume ~/magic_mirror/modules:/opt/magic_mirror/modules `
--name magic_mirror mm_tz

I'm sure not everyone will want to use one specific timezone, but this fixed the date issue I was having where the Calendar module was 6 hours off. Those commands are probably scriptable after the fact, too.

sylvaingirardbe commented 6 years ago

Afaik, if you want to set a timezone for a container you can pass the correct one on using the environment: TZ: 'Europe/Brussels' SET_CONTAINER_TIMEZONE: 'true' CONTAINER_TIMEZONE: 'Europe/Brussels'

No need to rebuild.

mneundorfer commented 5 years ago

@sylvaingirardbe I can confirm that, just tested it

dersch81 commented 5 years ago

@mneundorfer how can i do this? i'm not a docker pro :(

mneundorfer commented 5 years ago

Piece of cake: Just pass them via the docker run command, i.e. add

-e TZ=Europe/Berlin -e SET_CONTAINER_TIMEZONE=true -e CONTAINER_TIMEZONE=Europe/Berlin

I haven't actually checked yet whether actually all three of them are required.

If anyone using Compose stubles accross this in the future:

    environment:
      - TZ=Europe/Berlin
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Europe/Berlin
mneundorfer commented 5 years ago

Btw: If you want to check if it worked:

docker exec -it MM_CONTAINER_NAME /bin/date

If this does not return the date you expect, i.e. the date of your host, you are likely to run into "wrong calendar time" issues

dersch81 commented 5 years ago

thanks but that is showing the correc date Tue Dec 18 21:13:28 CET 2018

bastilimbach commented 5 years ago

Sorry guys, I hadn't much time to look into this issue but it's awesome to see your engagement with this! 👍 I myself did some researching and it looks like there are two different tweaks you need to make, to get this running.

To sync the system timezone you need to create a link between your host machines /etc/localtime file and the containers /etc/localtime file. This is accomplished by mounting the volume:

-v /etc/localtime:/etc/localtime:ro

Now, this fixes a lot of issues regarding system applications but not MagicMirror, because NodeJS isn't using the /etc/localtime file. It instead is looking for the environment variable TZ. (Referenz)

So ideally you should also set the environment variable TZ to your desired timezone:

-e TZ='Europe/Berlin'
bastilimbach commented 5 years ago

Ok, I did test these things and nothing worked. I just looked, if the timezone is set by MagicMirror and indeed it is. You can manually set the timezone in the config.js file. As soon as I did that, everything worked.

{
  module: "clock",
  position: "top_left",
  config: {
    timezone: "America/Campo_Grande"
  }
},

@dersch81 Could you test if this works for you?

bastilimbach commented 5 years ago

The right one is a running MagicMirror instance without the timezone setting set to any specific timezone: image

dersch81 commented 5 years ago

Hi, sorry i just could test it now. Unfortunatley it did not fix my issue with the calendar. The clock was always ok.

{
                        module: 'clock',
                        position: 'top_left',
                        config: {
                            timezone: "Europe/Berlin"
                        }

How can be the clock ok but the timezone of the calendar different? For your information i'm using the calendar with webcal from my private Nextcloud, one calendar is fetched from Office365. But with a "normal" MMM there is no problem with it. I have totally no idea how to debug this.

ax42 commented 5 years ago

My in-container date was on UTC-5 for some reason, using the -e switch fixed it.

dersch81 commented 5 years ago

Did you had a correct Clock but incorrect times of your calendar appointments?

My in-container date was on UTC-5 for some reason, using the -e switch fixed it.

ax42 commented 5 years ago

I've just noticed my calendar entries are also (still) off. I have an additional complication though - I have MMM running in a docker container on a server, and connecting to that (port 8080) has correct times. I have a client-only non-docker MMM Running on a pi (connected to the same server), and the times there are wrong. Any ideas?

ax42 commented 5 years ago

I needed to set the clock with -e on both client and server for everything to work.

bastilimbach commented 5 years ago

I guess the -e flag solves this issue. Therefore I’m closing this issue. If it still persist please reopen it.