diff forums/latest.py @ 1168:90e8cc6eff77

Fix ambiguous date errors in forum feeds.
author Brian Neal <bgneal@gmail.com>
date Sun, 05 Nov 2017 14:59:26 -0600
parents 7429c98c8ece
children e9f6a2c5c1de
line wrap: on
line diff
--- a/forums/latest.py	Tue Mar 07 19:33:18 2017 -0600
+++ b/forums/latest.py	Sun Nov 05 14:59:26 2017 -0600
@@ -55,8 +55,10 @@
 import logging
 import time
 
+from django.conf import settings
 from django.dispatch import receiver
 from django.template.loader import render_to_string
+import pytz
 import redis
 
 from forums.signals import post_content_update, topic_content_update
@@ -72,6 +74,8 @@
 # This controls how many updated topics we track
 MAX_UPDATED_TOPICS = 50
 
+SERVER_TZ = pytz.timezone(settings.TIME_ZONE)
+
 # Redis key names:
 POST_COUNT_KEY = "forums:public_post_count"
 TOPIC_COUNT_KEY = "forums:public_topic_count"
@@ -292,7 +296,9 @@
         post = json.loads(raw_post)
 
         # fix up the pubdate; turn it back into a datetime object
-        post['pubdate'] = datetime.datetime.fromtimestamp(post['pubdate'])
+        pubdate = datetime.datetime.utcfromtimestamp(post['pubdate'])
+        pubdate.replace(tzinfo=SERVER_TZ)
+        post['pubdate'] = pubdate
 
         posts.append(post)
 
@@ -474,7 +480,7 @@
         'title': post.topic.name,
         'content': content,
         'author': post.user.username,
-        'pubdate': int(time.mktime(post.creation_date.timetuple())),
+        'pubdate': int(time.mktime(post.creation_date.utctimetuple())),
         'forum_name': post.topic.forum.name,
         'url': post.get_absolute_url()
     }