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.
This commit is contained in:
John Doty 2024-11-22 16:11:45 -08:00
parent 1c81d6fcd4
commit 82fbae2486

View file

@ -1,5 +1,6 @@
# I guess this is it. # I guess this is it.
import asyncio import asyncio
import calendar
import dataclasses import dataclasses
import functools import functools
import hashlib import hashlib
@ -111,9 +112,10 @@ class Entry:
published = entry.get("updated_parsed") published = entry.get("updated_parsed")
if published is not None: if published is not None:
assert isinstance(published, tuple) assert isinstance(published, tuple)
# NOTE: Take insert_time if it's smaller; publish time errors generate # NOTE: Take insert_time if it's smaller; publish time errors generate
# posts from the future. # 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: else:
posted_at = int(insert_time) posted_at = int(insert_time)