Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#19835 closed Bug (wontfix)

django.utils.timezone.now should return local time when used with timezone.activate

Reported by: bach@… Owned by: nobody
Component: Core (Other) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I think using django.utils.timezone.now should return a timezone aware datetime object when used in conjunction with timezone.activate

For example,

timezone.activate('US/Pacific')
now = timezone.now()

now is a value that is UTC time instead of US/Pacific time. I understand that activate is used for rendering in templates but it's confusing when a user calls activate expecting that timezone to be activated and timezone.now doesn't obey that activation. If they aren't supposed to work together, I don't think they should belong in the same module.

Change History (2)

comment:1 by Aymeric Augustin, 11 years ago

Resolution: wontfix
Status: newclosed

timezone.activate() isn't used only for templates. It's used to change the current time zone. This affects QuerySet.datetimes for example.

timezone.now() uses neither the default not the current time zone. It works as documented and it would be quite disruptive to change its behavior.

Thanks for the proposal, but I'm not sure it's a good idea (using UTC here was a deliberate choice) and the drawbacks of a change certainly outweigh the advantages at this point.

Use timezone.localtime() to convert an aware datetime to another timezone.

comment:2 by rpq, 11 years ago

Version: 1.41.5

I should mention that using the timezone filter to force the conversion works on these datetime fields.

Version 0, edited 11 years ago by rpq (next)
Note: See TracTickets for help on using tickets.
Back to Top