timezone application aware

22 views
Skip to first unread message

Noumia Ngangoum

unread,
May 17, 2016, 4:51:24 PM5/17/16
to Django users

Hi, how really work timezoned application?

Let's  stay I set my app to be used worldwide, which means I have user in america, in africa, in europe...

Whatever operations they do within the database, all dates will be saved with timezone, right?
But how do you identify the timezone of a user? is that something that I should ask the user for and save it, and then use it whenever is necessary?
Why a TimeZoneMiddleWare is not available?

Stephen J. Butler

unread,
May 17, 2016, 5:07:40 PM5/17/16
to django...@googlegroups.com
I'm only experienced with the Oracle backend, but I believe only Postgres stores datetimes with timezone information. Otherwise, Django assumes all datetimes in the database are UTC. For the most portability you should assume that database values will be in UTC.

The user's local timezone is something you have to set, either in middleware or somewhere in the request processing.


I think there's no packages TimezoneMiddleware because how you do it is highly up to your app UI. Maybe you want to use GeoIP? Maybe you want to store it in the user's profile? Maybe you want a dropdown on each page? All of those are valid options.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6690c2f5-a921-4713-aa04-62a372a123f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Charette

unread,
May 17, 2016, 5:28:21 PM5/17/16
to Django users
Hi Noumia,


> Whatever operations they do within the database, all dates will be saved with
> timezone, right?

Django stores datetimes using the UTC timezone on all database backends.


> But how do you identify the timezone of a user? is that something that I
> should ask the user for and save it, and then use it whenever is necessary?
> Why a TimeZoneMiddleWare is not available?

You can use GeoIP[1] to attempt a timezone resolution based on the IP address
or you can ask your user about it and save it.

I suggest you have a look at django-sundial[2] which ships with the required
fields and middlewares to handle all of this.

Cheers,
Simon

[1] https://docs.djangoproject.com/en/1.9/ref/contrib/gis/geoip/
[2] https://github.com/charettes/django-sundial

David Alejandro Reyes Milian

unread,
May 17, 2016, 6:43:30 PM5/17/16
to Django users
I think this will really help you, worked a lot for me!!

http://tommikaikkonen.github.io/timezones/
Reply all
Reply to author
Forward
0 new messages