From 697d9af803c667841fb4c0cfe0832509c1541dff Mon Sep 17 00:00:00 2001 From: Patrick Gerken Date: Tue, 7 Sep 2010 12:03:18 +0000 Subject: [PATCH] Test that correct local time gets displayed. Since we now store the utc time in comments, we display code must not only format the date correctly, but show the correct local time. svn path=/plone.app.discussion/trunk/; revision=39727 --- plone/app/discussion/tests/test_comments_viewlet.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 2cf89e8..b954f1b 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import unittest +import time from datetime import datetime from AccessControl import Unauthorized @@ -421,6 +422,15 @@ class TestCommentsViewlet(PloneTestCase): def test_format_time(self): python_time = datetime(2009, 02, 01, 23, 32, 03, 57) + # Python Time must be utc time. There seems to be no too simple way + # to tell datetime to be of utc time. + # therefor, we convert the time to seconds since epoch, which seems + # to assume, that the datetime was given in local time, and does the + # correction to the seconds since epoch. Then time.gmtime returns + # a correct utc time that can be used to make datetime set the utc + # time of the local time given above. That way, the time for the + # example below is correct within each time zone, independent of DST + python_time = datetime(*time.gmtime(time.mktime(python_time.timetuple()))[:7]) localized_time = self.viewlet.format_time(python_time) self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM")