mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 09:33:46 +01:00
Merge pull request #2522 from discopatrick/date-value-field-validation-method
Date value field validation method
This commit is contained in:
commit
80f77aea4d
1 changed files with 9 additions and 10 deletions
|
|
@ -553,16 +553,15 @@ class Period(object):
|
|||
"""
|
||||
if not string:
|
||||
return None
|
||||
ordinal = string.count('-')
|
||||
if ordinal >= len(cls.date_formats):
|
||||
# Too many components.
|
||||
raise InvalidQueryArgumentTypeError(string,
|
||||
'a valid datetime string')
|
||||
date_format = cls.date_formats[ordinal]
|
||||
try:
|
||||
date = datetime.strptime(string, date_format)
|
||||
except ValueError:
|
||||
# Parsing failed.
|
||||
date = None
|
||||
for ordinal, date_format in enumerate(cls.date_formats):
|
||||
try:
|
||||
date = datetime.strptime(string, date_format)
|
||||
break
|
||||
except ValueError:
|
||||
# Parsing failed.
|
||||
pass
|
||||
if date is None:
|
||||
raise InvalidQueryArgumentTypeError(string,
|
||||
'a valid datetime string')
|
||||
precision = cls.precisions[ordinal]
|
||||
|
|
|
|||
Loading…
Reference in a new issue