diff --git a/plone/app/discussion/TODO.txt b/plone/app/discussion/TODO.txt index c0853a4..c86dba6 100644 --- a/plone/app/discussion/TODO.txt +++ b/plone/app/discussion/TODO.txt @@ -19,7 +19,7 @@ BASIC COMMENTING FUNCTIONALITY [ ] Fix temporary commenter's image css - [ ] Make comments viewlet format_time return localized time + [X] Make comments viewlet format_time return localized time [ ] Add i18n translations diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 399cdeb..9fd32c3 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -1,4 +1,5 @@ from datetime import datetime +from DateTime import DateTime from urllib import quote as url_quote @@ -125,10 +126,11 @@ class CommentsViewlet(ViewletBase): return '%s/login_form?came_from=%s' % (self.navigation_root_url, url_quote(self.request.get('URL', '')),) def format_time(self, time): - # Todo: return localized time - return time.strftime("%a, %d %b %Y %H:%M") - # XXX: Not working, returns None !!! - #return self.context.restrictedTraverse('@@plone').toLocalizedTime(time, long_format=True) + # We have to transform Python datetime into Zope DateTime + # before we can call toLocalizedTime + util = getToolByName(self.context, 'translation_service') + zope_time = DateTime(time.year, time.month, time.day, time.hour, time.minute, time.second) + return util.toLocalizedTime(zope_time, long_format=True) class AddComment(BrowserView): """Add a comment to a conversation diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 3f760d5..ebbd648 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -37,7 +37,9 @@ class CommentsViewletTest(PloneTestCase): self.viewlet = CommentsViewlet(context, request, None, None) def test_format_time(self): - pass + python_time = datetime(2009, 02, 01, 23, 32, 03, 57) + localized_time = self.viewlet.format_time(python_time) + self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM") def test_get_commenter_portrait(self):