I don't see any particular issues as long as you include the relevant test
cases changed.
TBH, the current validator is "good" because the default time widget
doesn't use the format with the space within, but, again, I don't see any
issues including the "parsing" for the "additional" format.
On Saturday, July 5, 2014 2:17:07 AM UTC+2, Wes Hall wrote:
>
> It appears as though '2pm' and '2 pm' validate differently while '2:00 pm'
> and '2:00pm' validate the same.
>
> In my quick testing, removing all spaces still allows the IS_TIME()
> validator to pass any tests.
>
> Am I missing any international time entry methods where the spaces would
> be critical or would this be an acceptable patch/fix?
>
> pre-fix
> >>> IS_TIME()('2pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2 pm')
> (datetime.time(2, 0), None)
> >>> IS_TIME()('02 pm')
> (datetime.time(2, 0), None)
> >>> IS_TIME()('2:00 pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2:00 pm ')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2 pm ')
> (datetime.time(2, 0), None)
> >>> IS_TIME()('2pm ')
> ('2pm ', 'Enter time as hh:mm:ss (seconds, am, pm optional)')
>
> post-fix
> >>> IS_TIME()('2pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2 pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('02 pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2:00 pm')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2:00 pm ')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2 pm ')
> (datetime.time(14, 0), None)
> >>> IS_TIME()('2pm ')
> (datetime.time(14, 0), None)
>
> gluon/validators.py
> class IS_TIME(Validator):
> ...
> def __call__(self, value):
> try:
> ivalue = value
> value = regex_time.match(value.lower().replace(' ',''))
> ...
>
>
> gluon/tests/test_validators.py
> ...
> rtn = IS_TIME()('2 pm')
> self.assertEqual(rtn, (datetime.time(14, 00), None))
> rtn = IS_TIME()('2 pm ')
> self.assertEqual(rtn, (datetime.time(14, 00), None))
> rtn = IS_TIME()('2pm')
> self.assertEqual(rtn, (datetime.time(14, 00), None))
> rtn = IS_TIME()('2pm ')
> self.assertEqual(rtn, (datetime.time(14, 00), None))
> ...
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.