Ticket #1188: formfields.TimeField.patch
File formfields.TimeField.patch, 1.4 KB (added by , 19 years ago) |
---|
-
core/formfields.py
746 746 747 747 class TimeField(TextField): 748 748 """A FormField that automatically converts its data to a datetime.time object. 749 The data should be in the format HH:MM:SS ."""749 The data should be in the format HH:MM:SS or HH:MM:SS.mmmmmm.""" 750 750 def __init__(self, field_name, is_required=False, validator_list=[]): 751 751 validator_list = [self.isValidTime] + validator_list 752 752 TextField.__init__(self, field_name, length=8, maxlength=8, … … 762 762 "Converts the field into a datetime.time object" 763 763 import time, datetime 764 764 try: 765 part_list = data.split('.') 765 766 try: 766 time_tuple = time.strptime( data, '%H:%M:%S')767 time_tuple = time.strptime(part_list[0], '%H:%M:%S') 767 768 except ValueError: # seconds weren't provided 768 time_tuple = time.strptime(data, '%H:%M') 769 return datetime.time(*time_tuple[3:6]) 769 time_tuple = time.strptime(part_list[0], '%H:%M') 770 t = datetime.time(*time_tuple[3:6]) 771 if (len(part_list) == 2): 772 t = t.replace(microsecond=int(part_list[1])) 773 return t 770 774 except (ValueError, TypeError): 771 775 return None 772 776 html2python = staticmethod(html2python)