From e58ca10e250dc75cfcc8e8a6e0f1a04b750bdf4a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 20 Dec 2017 21:36:11 -0600 Subject: [PATCH] Make jQuery time widget input even more flexible e.g. allow any of: * 01:30 PM * 1:30pm * 11 AM * 11am --- tailbone/forms2/types.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tailbone/forms2/types.py b/tailbone/forms2/types.py index 139aa784..977b8bc6 100644 --- a/tailbone/forms2/types.py +++ b/tailbone/forms2/types.py @@ -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])