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
This commit is contained in:
parent
a7b1eb7c10
commit
697d9af803
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from AccessControl import Unauthorized
|
from AccessControl import Unauthorized
|
||||||
@ -421,6 +422,15 @@ class TestCommentsViewlet(PloneTestCase):
|
|||||||
|
|
||||||
def test_format_time(self):
|
def test_format_time(self):
|
||||||
python_time = datetime(2009, 02, 01, 23, 32, 03, 57)
|
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)
|
localized_time = self.viewlet.format_time(python_time)
|
||||||
self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM")
|
self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user