Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#884 closed defect (worksforme)

Problems with international date handling

Reported by: Petar Marić <petar.maric@…> Owned by: Adrian Holovaty
Component: Template system Version: dev
Severity: major Keywords: translation date time i18n
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The code:

{% load i18n %}
{% blocktrans with object.pub_date|date:_("DATETIME_FORMAT") as date %}Published on {{ date }}{% endblocktrans %}

Spits out:

AttributeError at /category/xml/
'str' object has no attribute 'day'
Request Method: 	GET
Request URL: 	http://localhost/category/xml/
Exception Type: 	AttributeError
Exception Value: 	'str' object has no attribute 'day'
Exception Location: 	C:\Dev\Python24\lib\site-packages\django\utils\dateformat.py in d, line 114

Trace snip:

...

C:\Dev\Python24\lib\site-packages\django\utils\dateformat.py in d

 107. self.data = dt
 108. self.timezone = getattr(dt, 'tzinfo', None)
 109. if hasattr(self.data, 'hour') and not self.timezone:
 110. self.timezone = LocalTimezone(dt)
 111.
 112. def d(self):
 113. "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'"

 114. return '%02d' % self.data.day #Here we get the error

 115.
 116. def D(self):
 117. "Day of the week, textual, 3 letters; e.g. 'Fri'"
 118. return WEEKDAYS[self.data.weekday()][0:3]
 119.
 120. def F(self):

I was able to reproduce the error with LANGUAGE_CODE set to 'sr', 'en' and 'de'.

Change History (3)

comment:1 by hugo, 19 years ago

Resolution: worksforme
Status: newclosed

That sounds as if your pub_date attribute is actually a string, not a datetime object. I have used the following test program and it runs successfully:

from django.core.template import Template, Context
from django.utils.translation import activate

import datetime

src = """
{% load i18n %}
{% blocktrans with pub_date|date:_("DATETIME_FORMAT") as date %}Published on {{ date }}{% endblocktrans %}
"""

t = Template(src)
c = Context({'pub_date': datetime.datetime.now()})

print t.render(c)
activate('de')
print t.render(c)

This correctly produces the two lines:

Published on Nov. 23, 2005, 3:23 p.m.
Published on 23. Nov. 2005, 15:23

Please reopen if there really is a bug with the date formatting stuff.

comment:2 by Petar Marić <petar.maric@…>, 19 years ago

Sry, seems I had a typo error deep in my code.

comment:3 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top