Using Timezone

74 views
Skip to first unread message

Oleksa Stasevych

unread,
Feb 25, 2021, 7:26:21 PM2/25/21
to Helios Voting
Hi! I am wonder how to add timezone to the templates? By now everything is in UTC, while people are living in different locations. When I enable USE_TZ=True in settings.py I am constantly getting error "can't compare offset-naive and offset-aware datetimes". 
Thanks.

Oleksa Stasevych

unread,
Feb 25, 2021, 7:30:35 PM2/25/21
to Helios Voting
So, that means that TIME_ZONE variable cannot be used at all... :(

Warwick McNaughton

unread,
Feb 25, 2021, 7:36:17 PM2/25/21
to helios...@googlegroups.com
Couldn’t find USE_TZ in settings.py.   Just have TIME_ZONE = 'Pacific/Auckland'

Warwick

On 26/02/2021, at 1:26 PM, Oleksa Stasevych <oleksiy....@gmail.com> wrote:

Hi! I am wonder how to add timezone to the templates? By now everything is in UTC, while people are living in different locations. When I enable USE_TZ=True in settings.py I am constantly getting error "can't compare offset-naive and offset-aware datetimes". 
Thanks.

--
--
Helios Voting Google Group
To post: helios...@googlegroups.com
To unsubscribe: helios-votin...@googlegroups.com
More: http://groups.google.com/group/helios-voting?hl=en

---
You received this message because you are subscribed to the Google Groups "Helios Voting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to helios-votin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/helios-voting/5610f7bd-782b-41df-abcc-3e5092a2f941n%40googlegroups.com.

Oleksa Stasevych

unread,
Feb 25, 2021, 7:45:14 PM2/25/21
to Helios Voting
Ah, this goes from Shirley's repo... Well, in fact TIME_ZONE also doesn't influence anything, all the time settings are stored in UTC and they are not changed independently of the time zone. Eg, in settings I have TIME_ZONE=Europe/Kiev, I am adding starting voting time 01:00, and they are not starting at 01:00 EET (Kyiv time, GMT+02:00), but waiting for another 2 hours. Please, have a look at this screenshot.voting-not-started.jpg

Oleksa Stasevych

unread,
Feb 25, 2021, 8:59:03 PM2/25/21
to Helios Voting
Well, I imported timezone, replaced datetime.datetime.utcnow() with timezone.now(), as well as set up USE_TZ=True and now it shows the local time correctly depending on the time_zone.

BR, Oleksa

Warwick McNaughton

unread,
Feb 25, 2021, 11:38:22 PM2/25/21
to helios...@googlegroups.com

Kodondi shadrack

unread,
Jul 19, 2021, 10:30:52 PM7/19/21
to Helios Voting
kindly which file did you effect these changes?

Warwick McNaughton

unread,
Jul 20, 2021, 3:39:55 AM7/20/21
to helios...@googlegroups.com
I have not tried this myself.   These Django docs might help:


Looks like:
- enable timezone by USE_TZ=True in settings.py
- in files which have "import datetime” replace with "from django.utils import timezone
- in code replace “datetime.datetime" with “timezone" 

 


Reply all
Reply to author
Forward
0 new messages