mirror of
https://github.com/beetbox/beets.git
synced 2026-12-01 01:11:22 -06:00
Merge pull request #2522 from discopatrick/date-value-field-validation-method
Date value field validation method
This commit is contained in:
+9
-10
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user