Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ def _has_python_brace_format(string: str) -> bool:


def _parse_datetime_header(value: str) -> datetime.datetime:
match = re.match(r'^(?P<datetime>.*?)(?P<tzoffset>[+-]\d{4})?$', value)
# Handle blank or missing values
if not value or not value.strip():
return None

dt = datetime.datetime.strptime(match.group('datetime'), '%Y-%m-%d %H:%M')
match = re.match(r'^(?P<datetime>.*?)(?P<tzoffset>[+-]\d{4})?$', value.strip())
if not match or not match.group('datetime').strip():
return None

try:
dt = datetime.datetime.strptime(match.group('datetime').strip(), '%Y-%m-%d %H:%M')
except ValueError:
return None

# Separate the offset into a sign component, hours, and # minutes
tzoffset = match.group('tzoffset')
Expand Down