On Jun 1, 10:27 am, Artem Andreev <andreev.ar...@gmail.com> wrote:
> Hello!
>
> In django 1.4 with USE_TZ=true timezone.now() returns
> datetime.utcnow().replace(tzinfo=utc).
> Such datetime aware objects are handled properly in forms, templates and
> other places inside django framework.
> But when I prepare datetimes for ajax responses using strftime I always do
> localtime(timezone.now()).
> Same conversion I should do for any requests to external APIs which don't
> know about timezones.
>
> I couldn't find any discussions and arguments what timezone.now() should
> return.
>
> May be it will be more practical/comfortable for django users if
> timezone.now() will return localetime?
> What do you think about this?

The idea is that inside Python all datetimes are handled in time zone
UTC. The rule is simple: you should keep the datetimes in UTC as long
as you can. You should only convert the datetimes to other time zones
if it is required by:
  - You need to display the data to users
  - You need to pass the data to external systems which can't handle
UTC datetimes
  - You need to do calculations which depend on the timezone (the most
common one is "what date is it now in timezone X?".

So, timezone.now() returns the correct value. UTC-datetime is what you
want in Python. There maybe could be a shortcut function for local-
now.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to