Make jQuery time widget input even more flexible
e.g. allow any of: * 01:30 PM * 1:30pm * 11 AM * 11am
This commit is contained in:
parent
42b97d1e1a
commit
e58ca10e25
|
@ -37,11 +37,18 @@ class JQueryTime(colander.Time):
|
|||
def deserialize(self, node, cstruct):
|
||||
if not cstruct:
|
||||
return colander.null
|
||||
try:
|
||||
return colander.timeparse(cstruct, '%I:%M %p')
|
||||
except ValueError:
|
||||
|
||||
formats = [
|
||||
'%I:%M %p',
|
||||
'%I:%M%p',
|
||||
'%I %p',
|
||||
'%I%p',
|
||||
]
|
||||
for fmt in formats:
|
||||
try:
|
||||
return colander.timeparse(cstruct, '%I:%M%p')
|
||||
except:
|
||||
# re-try first format, for "better" error
|
||||
return colander.timeparse(cstruct, '%I:%M %p')
|
||||
return colander.timeparse(cstruct, fmt)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# re-try first format, for "better" error message
|
||||
return colander.timeparse(cstruct, formats[0])
|
||||
|
|
Loading…
Reference in a new issue