From 82fbae2486ba4414ad7b9ec5fbcafbb924030668 Mon Sep 17 00:00:00 2001 From: John Doty Date: Fri, 22 Nov 2024 16:11:45 -0800 Subject: [PATCH] time.mktime is not the inverse of time.gmtime, calendar.timegm is feedparser unhelpfully returns struct_time values in UTC and mktime assumes they're local. Ugh. --- cry/feed.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cry/feed.py b/cry/feed.py index 7f00fbe..856e2ef 100644 --- a/cry/feed.py +++ b/cry/feed.py @@ -1,5 +1,6 @@ # I guess this is it. import asyncio +import calendar import dataclasses import functools import hashlib @@ -111,9 +112,10 @@ class Entry: published = entry.get("updated_parsed") if published is not None: assert isinstance(published, tuple) + # NOTE: Take insert_time if it's smaller; publish time errors generate # posts from the future. - posted_at = min(int(time.mktime(published) * 1000), insert_time) + posted_at = min(int(calendar.timegm(published) * 1000), insert_time) else: posted_at = int(insert_time)