Skip to content

Commit 5765956

Browse files
authored
fix(workflows): use email.utils for RFC 822 date parsing (#10)
Python's strptime %Z doesn't reliably parse "GMT" timezone. Switch to email.utils.parsedate_to_datetime which handles RFC 822 dates correctly.
1 parent e893706 commit 5765956

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

.github/workflows/detect-blog-post-from-rss.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ jobs:
8080
import sys
8181
import xml.etree.ElementTree as ET
8282
import json
83-
import re
84-
from datetime import datetime
83+
from email.utils import parsedate_to_datetime
8584
import os
8685
8786
target_date = os.environ.get('TARGET_DATE', '')
@@ -105,14 +104,11 @@ jobs:
105104
continue
106105
107106
pub_date_str = pub_date_elem.text
108-
# Parse RFC 822 date format: "Wed, 25 Dec 2024 12:00:00 GMT"
107+
# Parse RFC 822 date format using email.utils (handles GMT correctly)
109108
try:
110-
pub_date = datetime.strptime(pub_date_str, '%a, %d %b %Y %H:%M:%S %Z')
111-
except ValueError:
112-
try:
113-
pub_date = datetime.strptime(pub_date_str, '%a, %d %b %Y %H:%M:%S %z')
114-
except ValueError:
115-
continue
109+
pub_date = parsedate_to_datetime(pub_date_str)
110+
except (ValueError, TypeError):
111+
continue
116112
117113
post_date = pub_date.strftime('%Y-%m-%d')
118114

0 commit comments

Comments
 (0)