Reputation: 13630
I package my python (flask
) application with docker. Within my app I'm generating UTC date with datetime
library using datetime.utcnow()
.
Unfortunately, when I inspect saved data with MongoDB Compass
the UTC date is offset two hours (to my local time zone). All my docker containers have time zone set to Etc/UTC
. Morover, mongoengine
connection to MongoDB uses tz_aware=False
and tzinfo=None
, what prevents on fly date conversions.
Where does the offset come from and how to fix it?
Upvotes: 5
Views: 8329
Reputation: 13630
Finally, after trying to prove myself wrong, and hairless head I found the cause and solution for my problem.
We are living in the world of illusion and what you see is not what you get!!!. I decided to inspect my data over mongo shell
client
rather than MongoDB Compass GUI
. I figure out that data that arrived to database contained correct UTC date. This narrowed all my previous
assumption that there has to be something wrong with my python application, and environment that the application is living in. What left was MongoDB Compass
itself.
After changing time zone on my machine to a random time zone, and refreshing collection within MongoDB Compass
, displayed UTC date changed to a date that fits random time zone.
Be aware that MongoDB Copass
displays whatever is saved in database Date
field, enlarged about your machine's time zone. Example, if you saved UTC time equivalent to 8:00 am
,
and your machine's time zone is Europe/Warsaw then MongoDB Compass
will display 10:00am
.
Upvotes: 16