Don't convert time when adding timezone in getter. Refactor time comparison in tests to correct direction (avoid comparing against negative deltas)
This commit is contained in:
parent
2df8ff4ea7
commit
0d643964a2
@ -142,7 +142,7 @@ class Comment(
|
||||
old_date = super(Comment, self).__getattribute__(attr)
|
||||
if old_date.tzinfo is None:
|
||||
# Naive dates were always stored utc
|
||||
return old_date.astimezone(timezone.utc)
|
||||
return old_date.replace(tzinfo=timezone.utc)
|
||||
return old_date
|
||||
return super(Comment, self).__getattribute__(attr)
|
||||
|
||||
|
@ -79,9 +79,9 @@ class ConversationTest(unittest.TestCase):
|
||||
self.assertEqual(len(tuple(conversation.getThreads())), 1)
|
||||
self.assertEqual(conversation.total_comments(), 1)
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date
|
||||
- datetime.now().astimezone(tz.gettz(default_timezone()))
|
||||
< timedelta(seconds=1),
|
||||
datetime.now().astimezone(tz.gettz(default_timezone()))
|
||||
- conversation.last_comment_date
|
||||
>= timedelta(seconds=0) <= timedelta(seconds=1),
|
||||
)
|
||||
|
||||
def test_timezone_naive_comment(self):
|
||||
@ -106,14 +106,12 @@ class ConversationTest(unittest.TestCase):
|
||||
comment.creation_date = datetime.utcnow()
|
||||
comment.modification_date = datetime.utcnow()
|
||||
|
||||
comment.reindexObject()
|
||||
|
||||
# Check that the timezone naive date is converted to UTC
|
||||
# See https://github.com/plone/plone.app.discussion/pull/204
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date
|
||||
- datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||
< timedelta(seconds=10),
|
||||
datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||
- conversation.last_comment_date
|
||||
>= timedelta(seconds=0) <= timedelta(seconds=1),
|
||||
)
|
||||
self.assertTrue(comment.creation_date.tzinfo, timezone.utc)
|
||||
self.assertTrue(comment.modification_date.tzinfo, timezone.utc)
|
||||
|
Loading…
Reference in New Issue
Block a user