0

My Django app receives POST API request with one of fields in body containing aware timestamp. If I log it's value right after deserialization I'm seeing the same time stamp but in different timezone.

Here's example of submitted request body:

{
    "event_timestamp": "2019-11-08T15:00:00+02:00",
    ...
}

Yet if I try to log the value of this field right after it passes deserialization I'm seeing:

> print(validated_data['event_timestamp'])

2019-11-08 14:00:00+01:00

TZ is enabled and configurred to CEST time zone:

USE_TZ = True
TIME_ZONE = 'Europe/Vienna'

I could make an assumption that Django is automatically converting received timestamp into defined timezone for entire project, but the result of such a conversion would have given me the same result:

2019-11-08T15:00:00+02:00 represented as CEST timezone is 2019-11-08T15:00:00+02:00

But instead I'm seeing conversion to 2019-11-08 14:00:00+01:00 which is time zone for London.

I understand that such conversions are normal process of Django handling aware datetime objects, but why does it convert received value to timezone that is neither set as default for the project itself nor has any relation to received timestamp?

Is there a way of managing default way of such convertions to timezone I manually define in settings.py or disable them all together?

Stan Reduta
  • 3,292
  • 5
  • 31
  • 55

1 Answers1

1

Your time zone isn't CEST, it's Europe/Vienna. Daylight savings time ends on October 27, 2019, so on November 8th the timezone offset will be +01:00. So Django is converting the time zone correctly.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
  • That totally slipped my memory!! So that also means that from October 27, 2019 Vienna (and the rest of western Europe for that matter) will be a `+01:00` zone? – Stan Reduta Oct 20 '19 at 13:08
  • 1
    Right, anyone using [`Europe/Vienna`](https://www.zeitverschiebung.net/en/timezone/europe--vienna) will shift to a `+01:00` offset. There are European countries that don't use Daylight Savings Time, but of course they would then be using a different time zone. – Kevin Christopher Henry Oct 20 '19 at 13:18