Convert dates with offset

main
Bob Mottram 2020-10-20 13:37:32 +01:00
parent fda4e294f8
commit 456b4202b1
2 changed files with 8 additions and 3 deletions

View File

@ -478,8 +478,13 @@ def convertRSStoActivityPub(baseDir: str, httpPrefix: str,
for dateStr, item in newswireReverse.items(): for dateStr, item in newswireReverse.items():
originalDateStr = dateStr originalDateStr = dateStr
# convert the date to the format used by ActivityPub # convert the date to the format used by ActivityPub
if '+00:00' in dateStr:
dateStr = dateStr.replace(' ', 'T') dateStr = dateStr.replace(' ', 'T')
dateStr = dateStr.replace('+00:00', 'Z') dateStr = dateStr.replace('+00:00', 'Z')
else:
dateStrWithOffset = \
datetime.datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z")
dateStr = dateStrWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ")
statusNumber, published = getStatusNumber(dateStr) statusNumber, published = getStatusNumber(dateStr)
newPostId = \ newPostId = \

View File

@ -344,7 +344,7 @@ def getRSSfromDict(baseDir: str, newswire: {},
published = published.replace(' ', 'T') published = published.replace(' ', 'T')
else: else:
publishedWithOffset = \ publishedWithOffset = \
datetime.datetime.strptime(published, "%Y-%m-%d %H:%M:%S%z") datetime.strptime(published, "%Y-%m-%d %H:%M:%S%z")
published = publishedWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ") published = publishedWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ")
try: try:
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ") pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")