Use UTC for feed item age calculation

This commit is contained in:
Marian Steinbach 2024-03-06 23:38:40 +01:00
parent c59db691a0
commit 58e3712e46
2 changed files with 6 additions and 4 deletions

View file

@ -5,6 +5,7 @@ Loads feeds linked from pages and collects information on the contained content
import logging
from time import mktime
from datetime import datetime
from datetime import timezone
import feedparser
@ -102,7 +103,7 @@ class Checker(AbstractChecker):
max_date = timestamp
if max_date is not None:
return datetime.fromtimestamp(max_date)
return datetime.fromtimestamp(max_date).replace(tzinfo=timezone.utc)
def find_first_entry(self, entries):
@ -117,4 +118,4 @@ class Checker(AbstractChecker):
min_date = timestamp
if min_date is not None:
return datetime.fromtimestamp(min_date)
return datetime.fromtimestamp(min_date).replace(tzinfo=timezone.utc)

View file

@ -6,6 +6,7 @@ from checks import html_head, page_content
from checks import load_feeds
from checks.config import Config
from datetime import datetime
from datetime import timezone
from pprint import pprint
@ -63,8 +64,8 @@ class TestFeed(unittest.TestCase):
self.assertEqual(result['http://example.com/feed.xml'], {
'exception': None,
'average_interval': 340359,
'first_entry': datetime(2003, 5, 30, 11, 6, 42),
'latest_entry': datetime(2003, 6, 3, 9, 39, 21),
'first_entry': datetime(2003, 5, 30, 11, 6, 42, tzinfo=timezone.utc),
'latest_entry': datetime(2003, 6, 3, 9, 39, 21, tzinfo=timezone.utc),
'num_entries': 2,
'title': 'Liftoff News',
})