#2633: django.utils.dateformat.DateFormat.O() returns wrong value
----------------------------+-----------------------------------------------
Reporter: mukappa | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Core framework | Version: 0.95
Severity: normal | Keywords:
----------------------------+-----------------------------------------------
from django.utils.dateformat
{{{
def O(self):
"Difference to Greenwich time in hours; e.g. '+0200'"
tz = self.timezone.utcoffset(self.data)
return "%+03d%02d" % (tz.seconds // 3600, (tz.seconds // 60) % 60)
}}}
This is wrong when {{{ tz.days == -1 }}}
I think this modified method should work
{{{
def O(self):
"Difference to Greenwich time in hours; e.g. '+0200'"
tz = self.timezone.utcoffset(self.data)
seconds = (tz.days * 24 * 60 * 60) + tz.seconds
return "%+03d%02d" % (seconds // 3600, (seconds // 60) % 60)
}}}
This session demonstrates the bug. {{{ df.O() }}} should output {{{ -0500
}}} not {{{ +1900 }}}
{{{
[EMAIL PROTECTED] 0 /home/mukappa/src/mysite
[1005]$ ./manage.py shell
Python 2.3.4 (#1, Feb 22 2005, 04:09:37)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime
>>> from django.utils.dateformat import DateFormat
>>> dt = datetime.now()
>>> dt
datetime.datetime(2006, 8, 30, 20, 48, 14, 86518)
>>> df = DateFormat(dt)
>>> df.O()
'+1900'
>>> df.r()
'Wed, 30 Aug 2006 20:48:14 +1900'
>>>
[EMAIL PROTECTED] 0 /home/mukappa/src/mysite
[1005]$ date -R
Wed, 30 Aug 2006 20:49:02 -0500
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/2633>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---