Hey,
I been doing a lot with timezone aware dates and I noticed that the mysql store will not allow you to store a datetime aware datetime. I was wondering if there is a reason why not convert theses dates to whatever is in the settings using astimezone. And then save that date.
Vitaly Babiy
A good reason? No. :-)
The practical reason is that the current implementation is old and
naive. Django's date/datetime/time fields were added very early in the
life of Django, so the current implementation is essentially the
simplest implementation that could possibly work at the time -- which
means no fancy handling when it comes to timezones.
Adding timezone sensitivity to Django's time/datetime fields is
something that has been on the project to-do list for almost as long
as I've been associated with the project (coming up on 5 years). If
you're interested in tackling this problem, here's a couple of things
to keep in mind:
* Backwards compatibility. Suddenly introducing a 'convert to local
timezone' behavior (or similar) will break any existing install.
* The interaction between application timezone and database server timezone.
* MySQL. Postgres supports timezones in date fields. MySQL doesn't.
We need to have a solid answer for how this feature will work on
databases that don't support timezone handling.
Also worth noting: by strange coincidence, you're the second person in
24 hours that has asked this question; FunkyBob was asking about
timezone support on IRC. This is something I'd love to see addressed;
if there are a couple of motivated people interested in the problem,
it may help to team up to solve it.
Yours,
Russ Magee %-)
As I see it there's two possible usage scenarios of date(time)s.
1. Those who don't need to care about timezones at all, for instance
because no dates are ever shown or shared, or all data will be from a
single timezone that doesn't utilise daylight savings time, or
accuracy better than two hours each way is not needed. This is
unfortunately what Python's datetime-module were designed for.
2. Everybody else.
1 is already solved today. There's more than one way to solve 2.
a) Convert to a single timezone on save (typically UTC but need not
be), and convert to a local timezone when showing. The question then
is whether it is relevant to save the timezone of the original
datetime. This might leak the location of where the input originated.
I currently store everything as UTC and throw away timezone info.
b) Store timezone directly, convert to local timezone when showing.
Then your dates are only as good as your locale-database since
daylight savings start/end tends to be changed by whoever has
political power at the moment.
c) <insert own bikeshed-blueprints here>
HM
> Adding timezone sensitivity to Django's time/datetime fields is
> something that has been on the project to-do list for almost as long
> as I've been associated with the project (coming up on 5 years).
Just noting existence of Brian Rosner's django-timezones as a datum,
you're very probably already aware of its existence, just mentioning it.
http://github.com/brosner/django-timezones
Not saying it's perfect, just that it exists and helps us (with some
bugfixing) deal with our time zone requirements. But we use postgresql.
We always use django settings.TIME_ZONE = 'UTC', settings.TIME_ZONE is
what django will currently assume - or tell (postgresql "SET TIME ZONE")
the database to use. We _do not_ use settings.TIME_ZONE to determine
what final presentation timezone to use for presentation of our (non
naive via django-timezones) app-internal datetimes to users.
utc_date = obj.created_at.replace(tzinfo=pytz.UTC)
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.