Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Fix the bug in detecting the exception if no date exists #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions dateutil/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,17 @@ def parse(self, timestr, default=None,
default = datetime.datetime.now().replace(hour=0, minute=0,
second=0, microsecond=0)
res = self._parse(timestr, **kwargs)
if res is None:
raise ValueError, "unknown string format"

repl = {}
for attr in ["year", "month", "day", "hour",
"minute", "second", "microsecond"]:
value = getattr(res, attr)
if value is not None:
repl[attr] = value

if len(repl) == 0:
raise ValueError, "unknown string format"

ret = default.replace(**repl)
if res.weekday is not None and not res.day:
ret = ret+relativedelta.relativedelta(weekday=res.weekday)
Expand Down