# HG changeset patch # User Brian Neal # Date 1509915566 21600 # Node ID 90e8cc6eff77d4af5aaa97d7af12ca4844b5da2f # Parent d551b60042137e1af47681e870b65a65e21ed875 Fix ambiguous date errors in forum feeds. diff -r d551b6004213 -r 90e8cc6eff77 forums/latest.py --- 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() }