On Thu, Sep 03, 2009 at 03:48:14PM -0700, Margie spake thusly: > What is the default when using a django DateTimeField? Does it not > save it in UTC? If it is not saving it in UTC, what is it saving it > in?
Python has two kinds of DateTime objects: naive and non-naive. Non-naive has timezone information with it. But the Django DateTimeField can only handle naive DateTime objects since MySQL cannot store time zones. So anytime you assign a time to a DateTimeField you have to convert it to a standard timezone and UTC is the most logical choice. > I thought that one of the things the DateTimeField did for you > was convert your input (whether form a user typed input or from a > server call to datetime.datetime.now ()) into some sort of internal > representation (UTC?). I think it would be nice if it did this automatically since that is the only thing that makes sense but it does not. Maybe someone out there is able to be 100% sure that their data will always be the same timezone so they don't want to inconvenience them by forcing everything to UTC so they have to do a conversion to localtime when they get their data back out. But I think such cases are exceedingly rare. So we are all stuck converting to UTC before doing a .save() on our models. > I thought that when I was using the date filter, that it was simply > converting that internal representation into my specificied text > format. Am I confused here? It does that but it does not do any timezone conversions. > I thought about putting the timezone in the profile but that does have > the disadvantage that if the user travels, they would have to update > their profile to get dates displayed in whatever location they are > at. I really don't like that since the people that will be using my > app are management, and they often travel (and probably won't want to > modify their profile all the time). There is no way around this afaik. They need to learn to do timezone conversions in their head or set a timezone in their profile. I label the timezone displayed prominently so they know to make the adjustment or change their profile. -- Tracy Reed http://tracyreed.org
pgpEwkmUhbJCF.pgp
Description: PGP signature