Code

Opened 14 months ago

Closed 14 months ago

Last modified 13 months 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.

Attachments (0)

Change History (2)

comment:1 Changed 14 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 Changed 13 months ago by rpq

  • Version changed from 1.4 to 1.5

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

Version 0, edited 13 months ago by rpq (next)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.