From 3a1d5649927ffe33f98cc2aa1c598a9cce9b62bb Mon Sep 17 00:00:00 2001 From: pictuga Date: Thu, 22 Apr 2021 21:51:00 +0200 Subject: [PATCH] feeds: fix time zone handling --- morss/feeds.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/morss/feeds.py b/morss/feeds.py index 9f56c23..f25b355 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -508,24 +508,28 @@ class ParserHTML(ParserXML): def parse_time(value): + # parsing per se if value is None or value == 0: - return None + time = None elif isinstance(value, basestring): if re.match(r'^[0-9]+$', value): - return datetime.fromtimestamp(int(value), tz.tzutc()) + time = datetime.fromtimestamp(int(value)) else: - return dateutil.parser.parse(value).replace(tzinfo=tz.tzutc()) + time = dateutil.parser.parse(value) elif isinstance(value, int): - return datetime.fromtimestamp(value, tz.tzutc()) + time = datetime.fromtimestamp(value) elif isinstance(value, datetime): - return value + time = value - else: - return None + # add default time zone if none set + if time is not None and time.tzinfo is None: + time = time.replace(tzinfo=tz.tzutc()) + + return time class ParserJSON(ParserBase):