feeds: fix time zone handling

master
pictuga 2021-04-22 21:51:00 +02:00
parent 6880a443e0
commit 3a1d564992
1 changed files with 11 additions and 7 deletions

View File

@ -508,24 +508,28 @@ class ParserHTML(ParserXML):
def parse_time(value): def parse_time(value):
# parsing per se
if value is None or value == 0: if value is None or value == 0:
return None time = None
elif isinstance(value, basestring): elif isinstance(value, basestring):
if re.match(r'^[0-9]+$', value): if re.match(r'^[0-9]+$', value):
return datetime.fromtimestamp(int(value), tz.tzutc()) time = datetime.fromtimestamp(int(value))
else: else:
return dateutil.parser.parse(value).replace(tzinfo=tz.tzutc()) time = dateutil.parser.parse(value)
elif isinstance(value, int): elif isinstance(value, int):
return datetime.fromtimestamp(value, tz.tzutc()) time = datetime.fromtimestamp(value)
elif isinstance(value, datetime): elif isinstance(value, datetime):
return value time = value
else: # add default time zone if none set
return None if time is not None and time.tzinfo is None:
time = time.replace(tzinfo=tz.tzutc())
return time
class ParserJSON(ParserBase): class ParserJSON(ParserBase):