Answer the question
In order to leave comments, you need to log in
How to correctly display time after changing timezones?
There is an application on Django. Some models use a DateTimeField, which corresponds to PostgreSQL's timestamp with timezone type.
The app works in Europe/Moscow time zone. Prior to the tz_data update, the application was running at an offset of +4. That is, if I saved 01-01-2014 in postgres, it was written 01-01-2014 00:00:00+04.
After updating tz_data, the application runs with an offset of +3. If now, let's say, we extract some record by id, then in the response, 12-31-2013 will come in the date field (because postgres will transfer the time to the application zone 12-31-2013 23:00:00+03) . Accordingly, the filter breaks down by date. Now, when selecting for 01-01-2014, I will not receive records that I previously recorded by this date.
Quickly, this omission was patched up by setting a timezone with the old offset in the application (in our case, Asia / Dubai). Filters remarkably work, dates are given normally. BUT, there was another problem. In some models, the change time is written (ie the current time). The datetime.now() function retrieves the current server time, say 15:00, and then adds one more hour (because the server is in timezone +3 and the application is in +4). As a result, the user sees that he edited his entry at 16:00, although it is now 15:00.
Question: how to tame all the same belts. I would like the application to work in its +3 time zone and at the same time the old saved records would not shift back an hour over time.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question