Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respecting Local Time in Django 1.11 #60

Open
sirberus opened this issue Aug 21, 2017 · 3 comments
Open

Respecting Local Time in Django 1.11 #60

sirberus opened this issue Aug 21, 2017 · 3 comments

Comments

@sirberus
Copy link

sirberus commented Aug 21, 2017

I was tweaking calendarium 1.3.4 today to work with my Django 1.11 site and I noticed that, after 5pm PST, it was already saying that "today" was tomorrow. As in, the day for which current = True in views.py was the next day. Realizing that this was a UTC/timezone issue I began investigating.

Though now() from django.utils.timezone will display as local time if printed, the calls to now().date() seem to be lose the timezone and revert to UTC. Print now().time() for a very blatant example.

I discovered that by importing localtime() from django.utils.timezone and wrapping each now() call as localtime(now()) this solved the issue. There may be a prettier way but this does work, importing Django's TIME_ZONE from settings.py and forcing .date() and .time() to remain timezone-aware.

@Tyrdall
Copy link
Member

Tyrdall commented Aug 21, 2017

@sirberus Mhm sounds reasonable. Can you provide a pull request. We don't have any free capacities to work on this app right now. Thanks!

@khrizo
Copy link

khrizo commented Jun 1, 2018

Having the same issue as Sirberus, the event shows the next day trying the mentioned solution didn't work for me. Any help is appreciated.

@sirberus would you be able to share your views.py

@khrizo
Copy link

khrizo commented Jun 4, 2018

Ended doing the folllowing:

Original code
occurrences = filter(lambda occ, date=date: occ.start.replace(hour=0, minute=0, second=0, microsecond=0) == date, all_occurrences)

changed to since i'm in Est time:

occurrences = filter(lambda occ, date=date: (occ.start - timedelta(hours = 4, minutes = 00)).replace(hour=0, minute=0, second=0, microsecond=0) == date, all_occurrences)

this way, every event is now shown in the right day; however the date in the URL is a day ahead due to UTC storage, I guess using a slug solution would be a good approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants