Django

Code

Ticket #7209 (new)

Opened 2 months ago

Last modified 3 weeks ago

time_zone conflict.. datetime.now() (in django shell) shows 3 hours earlier

Reported by: alperkanat@gmail.com Assigned to: nobody
Milestone: Component: Uncategorized
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by ramiro)

to make it clear, I replicate the problem:

[02:29] (tunix@penguix raptiye)$ date
Cts May 10 02:31:57 EEST 2008
[02:31] (tunix@penguix raptiye)$ python
Python 2.5.2 (r252:60911, Feb 23 2008, 21:20:32) 
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2008, 5, 10, 2, 32, 7, 410947)
>>> datetime.utcnow()
datetime.datetime(2008, 5, 9, 23, 32, 10, 255636)
>>> 
[02:32] (tunix@penguix raptiye)$ ./manage.py shell
Python 2.5.2 (r252:60911, Feb 23 2008, 21:20:32) 
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2008, 5, 9, 23, 32, 25, 624929)
>>> datetime.utcnow()
datetime.datetime(2008, 5, 9, 23, 32, 29, 45600)
>>>

i've just set system time to UTC and it still doesn't work.. i'm using Europe/Istanbul as the timezone.. django would work fine a few weeks before..

Attachments

Change History

05/09/08 18:44:09 changed by Collin Grady <cgrady@the-magi.us>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

I am also seeing strange behavior:

$ date
Fri May  9 16:35:09 PDT 2008

$ cat settings.py | grep TIME_ZONE
TIME_ZONE = 'Europe/Helsinki'

$ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2008, 5, 9, 16, 35, 16, 602801)
>>> datetime.utcnow()
datetime.datetime(2008, 5, 9, 23, 35, 19, 770471)
>>>

$ ./manage.py shell
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2008, 5, 10, 2, 35, 37, 190599)
>>> datetime.utcnow()
datetime.datetime(2008, 5, 9, 23, 35, 38, 390818)
>>>

# changed settings.TIME_ZONE to "PDT" or "America/Pacific"

$ ./manage.py shell
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35) 
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime                                                                                    
>>> datetime.now()                                                                                                   
datetime.datetime(2008, 5, 9, 23, 39, 49, 115522)
>>> datetime.utcnow()                                                                                    
datetime.datetime(2008, 5, 9, 23, 39, 50, 27832)
>>> 

With the first TIME_ZONE setting, it seemed it might be respecting it, but changing to anything for Pacific time made it switch to UTC in manage.py shell

06/16/08 11:11:30 changed by ramiro

  • description changed.

Add/Change #7209 (time_zone conflict.. datetime.now() (in django shell) shows 3 hours earlier)




Change Properties
Action